gramjs
gramjs copied to clipboard
replyMarkup and inline buttons
Hi, How Could I send buttons inline or as keyboard with my message? Tried to import Button from telegram but does not work! Thanks I send the message like this now
await client.sendMessage( CHAT_ID , { message: 'THE MESSAGE', })
You can use buildReplyMarkup
import {Button} from "telegram";
// PS this function is not async
const markup = client.buildReplyMarkup(Button.inline("Hello!"));
await client.sendMessage(chat, {
message: "click me!",
buttons: markup,
}
you can find more at https://gram.js.org/beta/classes/client_telegramclient.telegramclient.html#buildreplymarkup
Thanks @painor
I use require not import.. so this does not work with me!
const { Button, TelegramClient } = require("telegram");
Can you try doing this
const { Button } = require("telegram/tl/custom/button");
Thanks.. I required that.. But the button not showing anyway.. I am not sure why!
const { Button } = require("telegram/tl/custom/button");
const markup = client.buildReplyMarkup(Button.inline("Hello!"));
await client.sendMessage(chat, {
message: "click me!",
buttons: markup,
}
Are you using a bot account? only bots can use buttons
I have apiId and apiHash created from app page. and I use my account to login and save session.
await client.start({
phoneNumber: async () => await input.text("number?"),
password: async () => await input.text("2F password?"),
phoneCode: async () => await input.text("Code?"),
onError: (err) => console.log(err),
});
I have create bot as well, using botFather but not sure how I make the bot send the message! as I saw my account can send the message so I did not use the other bot.
Thanks works fine with Bot account :-)
await client.start({
botAuthToken: "",
});
https://github.com/gram-js/gramjs/blob/master/examples/main.ts#L40
how to use button with command