所以,我正在用Node中的Telegraf.js制作一个电报机器人,而机器人需要用户的电话号码,而在Telegraf中,请求电话号码的一种方法是这样的
ctx.reply(
"Phone number is required",
{
...Markup.keyboard([
Markup.button.contactRequest("Send Contact"),
]).resize(),
}
);这很好,但是我不知道如何处理联系人请求的结果,我尝试使用bot.hears,把它当作回调按钮bot.hears
bot.hears("Send Contact",(ctx)=>{
console.log("contact received")
})但是这不起作用,所以我想知道是否有一种特殊的方法来处理Markup.button.contactRequest的响应
发布于 2022-10-10 05:03:26
我找到了解决办法。希望它也能帮到你
await ctx.telegram.sendMessage(ctx.chat.id, "Some text", {
parse_mode: "Markdown",
reply_markup: {
one_time_keyboard: true,
keyboard: [
[
{
text: "Share Phone Number",
request_contact: true,
},
{
text: "Cancel",
},
],
],
force_reply: true,
},
});
bot.on("contact", (ctx: any) => {
const contact = ctx.message.contact.phone_number;
console.log("Hello Contact",contact);
});https://stackoverflow.com/questions/73107698
复制相似问题