Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get contacts on Telegram

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?

like image 838
Warlord Avatar asked May 02 '17 09:05

Warlord


1 Answers

  1. 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***** }
    
    })
    
like image 136
Nelson Bwogora Avatar answered Oct 15 '22 03:10

Nelson Bwogora