View this repository and README file for more information: https://github.com/apal21/Telegram-Bot-Custom-Keyboard-Node.js
- After setting up the basic Telegram Bot, in this repository I've created an array
auth_users
on Line #8 - Inside this array remove all unnecessary User IDs and add your own IDs.
- If there is a user whose id is not inside this array, he/she will always get the response
Unauthorized User
. /id
: Send this message to your bot to get your own User ID.
- In this
node-telegram-bot-api
package, callback ofonText
method's first argument is the message received by the bot. - You can see its content by printing this
msg
object. - Here
msg.from.id
gives the User Id andmsg.from.username
gives the Username of the user. - We can also use Username to authenticate users but in Telegram it is not mandatory to have a Username but the User ID will always be there. (Safe Game...)
authenticate_users
function at the bottom of theindex.js
file will loop through all the User IDs and if any of the User ID matches with the ID from the message is sent, it returnstrue
else it returnsfalse
.