I am trying to get chat from one user using my telegram bot. Below is my code so far
const { Telegraf } = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.telegram.getChat('username', async (ctx) =>{'incoming message ', console.log(ctx.message.tesx)})
from Doument
(method) Telegram.getChat(chatId: string | number): Promise<ChatFromGetChat>
Get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
@param chatId — Unique identifier for the target chat or username of the target supergroup or channel (in the format
@channelusername — )
so in my parameter i use the username of that particular chat (not group chat, only 1 person) but it return chat not found.
Any advice is appreciated
You have to pass the chat and chat id for the getChat instead of just passing a string.
bot.telegram.getChat(ctx.message.chat.id, ctx.message.chat, async (ctx) =>
{'incoming message ', console.log(ctx.message.tesx)})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.