-1
bot.command("greeting", (ctx) => ctx.reply("Hello users, what's your name?");

ctx.reply("Hello Alex nice to meet you!")
Filburt
  • 17,626
  • 12
  • 64
  • 115
Vieendya
  • 3
  • 3

1 Answers1

0

No matter which social bot you are using (viber, telegram, telegraf etc) it requires user to be subscribed on its incoming list and then you will be able to use ctx.message.chat.id to send message on specific registered user.

telegraf example:

bot.on('text', (ctx) => {
  // Explicit usage
  ctx.telegram.sendMessage(ctx.message.chat.id, `Hello ${ctx.state.role}`)

  // Using context shortcut
  ctx.reply(`Hello ${ctx.state.role}`)
})

Moreover if there is a first time a user is sends a word to bot, there is a need to do the following.

bot.hears('/Hi', (ctx)=> ctx.reply('Hello ' + getName(ctx.message.from))

function getName(user) {
    return user.first_name || user.last_name;
}

If the bot receives a "Hi" it will reply with "Hello -user name-"

George Gotsidis
  • 426
  • 4
  • 15