I use node.js module for Telegram bot. I'm trying to get the user's contact on telegram using telegram API. Telegram API has 2 types: Bot API and Telegram API.
I think Bot API can not get the user's contacts.
In Telegram API there is the method contact.getContacts
. But I don't know how to use it.
How can I get the contacts on Telegram?
this code will give you the contact, user shares his/her contact with your bot , user types command '/special' will be prompted with button to allow bot to get contact and on agreeing in your node server you may log contact info remember to declare Markup ---->
//declare Markup
const {Extra,Markup}= Telegraf;
bot.command('special', (ctx) => {
return ctx.reply('Special buttons keyboard', Extra.markup((markup) => {
return markup.resize()
.keyboard([
markup.contactRequestButton('contact')
])
}))
})
//listens for the click on contact button
bot.on('contact', (ctx) => {
console.log(ctx.update.message.contact);
//logs { phone_number: '254*******',
//first_name: 'nelsonBlack',
//user_id: 73***** }
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With