Package Exports
- tg-resolve
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tg-resolve) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
👤 tg-resolve
A light Node.js Library that resolves Telegram usernames and/or ids to a complete User or/and Chat JSON object(s)
Powered by PWRTelegram API
Background
The official Telegram API does not allow bots to resolve usernames/ids out of the box. One is forced to create his/her own database so as to resolve usernames. Resolving of usernames is particularly useful in that a bot is able to get a user/chat id of a person or groub it hasn't even seen! Unlike before where a bot is only able to see a person if it has ever recieved his/her message whether in private or in a group.
Useful Scenarios
- Group administration bots
- In a bot which has lost its database, but users had previously started the bot
- General resolving to get user details e.g UResolverBot
- And much more!
Install
$ npm install tg-resolve --save
Usage
const tgresolve = require("tg-resolve");
// using the 'bare' function
tgresolve(token, "@kamikazechaser", function(error, result) {
// ... handle error ...
console.log(result.id);
});
// you can create a client (referred to as 'resolver')
// that you can repeatedly use
const resolver = new tgresolver.Tgresolve(token);
// using the 'resolver'
resolver.tgresolve("@kamikazechaser", function(error, result) {
// ... handle error ...
console.log(result.id);
});
Refer to example.js for a more comprehensive guide
- As of v1.2.0, you will need your own bot token!
- As of v1.3.0, you can pass in your own pwrtg url!
tgresolve(token, username[, options], callback)
Resolve the username
to a Result.
- token (String): Telegram bot token
- username (String)
- options (Object, Optional)
- url (String): custom PWRTelegram API URL
- callback (Function):
- signature:
callback(error, result)
- signature:
resolver = new tgresolve.Tgresolve(token[, options])
Create a client/resolver.
- token (String): Telegram bot token
- options (Object, Optional): same as above
resolver.tgresolve(username, callback)
Resolve the username
to a Result, using the client.
- username (String)
- callback (Function): same as above
Result
When resolving for a Group/Channel
{
id: -1001065761006,
title: "End Of The World Party",
username: "EOTWGroup",
type: "supergroup",
when: "2016-10-18 11:22:56"
}
When resolving for a User
{
id: 58258161,
first_name: "John",
username: "john_doe",
type: "private",
last_name: "Doe",
when: "2016-10-18 11:22:56"
}
Issues And Contribution
Fork the repository and submit a pull request for whatever change you want to be added to this project. If you have any questions, just open an issue.