This repository has been archived by the owner on May 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Adding Redirections
Aditya Thebe edited this page Nov 10, 2018
·
2 revisions
/add <source> <destination>
/**
* @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)
This function should be called only after making sure that there are 2 parameters passed to the /add
command.
Bot the source and destination should be provided in one of the two formats:
- Username should start with
'@'
- Invitaion Links should start with
'https://t.me/joinchat'
or't.me/joinchat'
If the source or destination is not in the above format, checkSourceEntity
will throw an error.
Types of Response at this stage
// Response for username
{
'username': 'adityathebe',
}
// Response for invitation link
{
'hash': 'xyzjskdl123'
}
Free users are limited to 10 redirections while premium users have no limitation for redirections. If in case, the user is not stored in the db at this state and error will be thrown
Need to make sure the entities are valid before we send a join request to them because
- Even if the agent is already in the entity, sending join request will result in an error
- Sending join request to invalid entity will result in an error
ForwardAgent.getEntity(entity)
Should return an object in case of success. In any other case, will return an error object
// User Entity
{
joined: Boolean,
entity: {
type: 'user',
title: String,
chatId: Number,
accessHash: String,
bot: Boolean,
}
}
// Channel Entity
{
joined: Boolean,
entity: {
type: 'channel',
chatId: Number,
title: String,
accessHash: String,
megagroup: Boolean,
adminRights : Boolean,
}
}
// Group Entity
{
joined: Boolean,
entity: {
type: 'group',
chatId: String,
title: String,
accessHash: String,
}
}
// Unreachable Invitation link
{
joinable: Boolean,
entity: null
}
// Private Entity
ForwardAgent.joinPrivateEntity(hash)
// Public Entity
ForwardAgent.joinPublicEntity(entity)
database.getRedirection(owner)
Store redirection
- src_title
- src_chat_id
- src_username
- dest_title
- dest_chat_id
- dest_username
- owner
/**
* Verifies that the source/destination is in one of the two valid formats
* -- If it's a public entity (username), it should start with "@"
* -- If it's a private entity (invitation link), it should start with t.me/joinchat/<HASH>
* @param {string} entity username or invitation link
* @returns {Object}
*/
checkSourcePattern(entity)