Giter Club home page Giter Club logo

scam-chat's Introduction

Scam Chat

Table of contents

About

Scam chat is a service that facilitates the sending and receiving messages for canary accounts accounts in order to enable pseudonymous online chats . It uses the GramJS client library to connect to Telegram

Getting Started

Prerequisites

Usage

Account API setup

  • Navigate to tests/telegram_api_demo and follow the corresponding README

Project setup

  1. Run npm install for project dependencies

  2. Create a .env file within the root directory to specify a MongoDB connection string and application port number

    • MONGODB_CONNECTION is a string can be local (mongodb://localhost:27017) or remote
    • PORT can any available local port number of choice. Generally, port numbers 808X are available.
    • RELEASE_TIMEOUT is the time in seconds that a chat session remains assigned to a user before it is released back into the pool of available sessions.
    • ARCHIVE_TIMEOUT is the time in seconds that a chat session remains available before it is archived

    An example of a possible .env configuration:

MONGODB_CONNECTION="mongodb://localhost:27017"
PORT=8081
RELEASE_DURATION=86400 # 1 day
ARCHIVE_DURATION=259200 # 3 days
  1. Start the application locally with npm run start. Alternatively, you can also build and run the projectwith Docker using the provided Dockerfile and docker-compose.yml

Roadmap

TBA

Contributing

NA

License

See LICENSE.md

scam-chat's People

Contributors

charlotte-wt avatar clairverbot avatar emmaneugene avatar

Stargazers

 avatar  avatar

Forkers

emmaneugene

scam-chat's Issues

Bug where all telegram users are returned instead of the specific one

Routing issue in scam_chat/app/routes/tele_user.route.js

// Retrieve a single user with number
router.get('/:user_id', getUserByNum);

According to the code in scam_chat/app/controllers/tele_user.controller.js it should be

// Retrieve a single user with number
router.get('/:phone_num', getUserByNum);

Additionally, able to refactor to not use in for a single user in scam_chat/app/controllers/tele_user.controller.js.

Original Code:

// Find a single User by phone_num
export const getUserByNum = async (req, res) => {
  try {
    const user = await UserModel.find({
      members: { $in: [req.params.phone_num] }
    });
    res.status(200).json(user);
  } catch (error) {
    res.status(500).json(error);
  }
};

Refactored Code:

// Find a single User by phone_num
export const getUserByNum = async (req, res) => {
  try {
    const user = await UserModel.find({
      phone_num: req.params.phone_num
    });
    res.status(200).json(user);
  } catch (error) {
    res.status(500).json(error);
  }
};

Performance issue with retrieving chats / messages

  1. $in operator is not necessary if we are matching only one phone number
  2. More efficient to have a latestMessage field in the chats collection, which would allow us to retrieve just the latest message for each chat without having to retrieve all the chat messages
  3. Currently, we’re manually grouping the chat messages on the frontend based on the dates, doing it through mongodb’s aggregation pipeline might be faster and cleaner. Group the results before returning the data and sort too.
    Notion:
    https://www.notion.so/UI-Layout-for-Chat-43feabaa9f494c4f89f87bcd4d1acb53?pvs=4
try {
    const chatDetails = await ChatModel.find({
      phone_num: req.params.phone_num

    }).sort({updatedAt: -1});
}
  res.status(200).json(chatDetails);
} catch (error) {
  res.status(500).json(error);
}

Full test flow

  • Full test suite with setup and teardown to demonstrate session management

Session assignment

To avoid dealing with complex race conditions, assignment of new sessions will be performed by the SessionController object, instead of allowing users to choose or input handles for initiating chats

Bug where senderId may not be contactId

If the canary account is the last to send a message, the the senderId will be the canary account's ID instead of the contact's ID.

      const totalMsgs = msgs.total;
      const sender = await msgs[0].getSender();
      const contactName = sender.firstName;

      const chat = new ChatModel({
        phone_num: req.params.phone_num,
        contact_name: contactName,
        total_msgs: totalMsgs,
        chat_id: chatId
      });

New session creation

A new session should be created whenever a new chatId is identified within a canary account's list of chats

TODO modify updateChatList() in chat_list.controller.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.