0

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

yongchang
  • 503
  • 6
  • 18

2 Answers2

0

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)})
Alazar-dev
  • 94
  • 2
  • 5
0

One Thing to Check here is if the Channel or Group is Private. Make sure the Channel is Public. and this is how you use the send message function.

await bot.telegram.sendMessage('@channel_username', 'message text', Markup.inlineKeyboard([
{text: 'button text',  url: `https://t.me/xxxx_bot?start=${data.id}`}]);)