Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Adding Redirections

Aditya Thebe edited this page Nov 10, 2018 · 2 revisions

Command

/add <source> <destination>

Function defintion

/**
 * @param {String} sender Chat id of the owner
 * @param {String} source Username / Link of Source
 * @param {String} destination Username / Link of Destination
 */
addRedirection (sender, source, destination)

Procedure

1. Check the entity format.

  • Usernames must start with '@"
  • Invitation links must start with 'https://t.me/joinchat' or 't.me/joinchat'
  • Should return an object

Example Response

// Response for username
{
  'username': 'adityathebe',
}

// Response for invitation link
{ 
  'hash': 'xyzjskdl123'
}

// If neither
{
  'error': 'Invalid format'
}

2. Get both the entities from the API

ForwardAgent.getEntity(entity)

Need to make sure the entities are valid before we send a join request to them.

NOTE: This check is important because a request to join an entity where the agent is already a participant of will result in an error.

Should return an object in case of success

// User Entity
{
  joinable: true,
  accessHash: 'kjsdfkasd1234kl1j',
  bot: true, // false
  title: 'adityathebe',
  chatId: '491823011',
}

// Channel Entity
{
  joinable: true,
  chatId: '023129382',
  title: 'Best Channel',
  accessHash: 'kjasdf902134j',
  megagroup: true, // false
  left: true, //false
}

// Unreachable Invitation link
{
  joinable: true,
}

In any other case, will return an error object

3. Send Join Request

// Private Entity
ForwardAgent.joinPrivateEntity(hash)

// Public Entity
ForwardAgent.joinPublicEntity(entity)

4. Check if redirection already exists for the user

database.getRedirection(owner)

5. Store to database

Store redirection

  • src_title
  • src_chat_id
  • src_username
  • dest_title
  • dest_chat_id
  • dest_username
  • owner
Clone this wiki locally