skip to Main Content

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?

2

Answers


  1. Bot API can get contact info too; I think it is easier in this case.

    You can try reply keyboard with request_contact. If the user clicks it, you will receive message update with Contact field.

    Login or Signup to reply.
    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***** }
      
      })
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search