Answer the question
In order to leave comments, you need to log in
How to forward the user's response to the bot to the tg group?
The bottom line is that when a user sends his contacts to the bot, you need to forward his message to the group. I am using the telegraf js framework. Here's how I implemented it:
const nameGroup = -1001709735749; // group id where messages should be forwarded to
bot.on("contact", async (ctx) => {
const chatId = ctx.chat.id;
const userContact = ctx.message.contact.phone_number;
const userName = ctx.message. contact.first_name;
return await ctx.reply(
`Thank you ${userName}! ${userContact} will be contacted as soon as possible!`
),
await ctx.forwardMessage(nameGroup, chatId, userContact);
});
What can be a benefit?
C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\core\network\client.js:263
throw new error_1.default(data, { method, payload });
^
TelegramError: 400: Bad Request: chat not found
at Telegram.callApi (C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\core\network\client.js:263:19 )
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\index.js:389:3
at async execute (C:\Users \Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\composer.js:458:17)
at async C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\composer.js:459:21
at async execute (C:\Users\Palata13\Documents\Practice\2021\5sher \it5SHERbot\node_modules\telegraf\lib\composer.js:458:17)
at async C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\composer.js:459:21
at async execute (C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\composer.js:458:17)
at async C:\Users\Palata13\Documents\Practice\2021\5sher \it5SHERbot\node_modules\telegraf\lib\composer.js:459:21
at async execute (C:\Users\Palata13\Documents\Practice\2021\5sher\it5SHERbot\node_modules\telegraf\lib\composer.js:458:17 ) {
response: {
ok: false,
error_code: 400,
description: 'Bad Request: chat not found'
},
on: {
method: 'forwardMessage',
payload: {
chat_id: -1001709735749,
from_chat_id: 764937841,
message_id: 2249
}
}
}
[nodemon] app crashed - waiting for file changes before starting...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question