gramjs icon indicating copy to clipboard operation
gramjs copied to clipboard

replyMarkup and inline buttons

Open Wooody82 opened this issue 3 years ago • 7 comments

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', })

Wooody82 avatar Dec 25 '21 20:12 Wooody82

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

painor avatar Dec 25 '21 21:12 painor

Thanks @painor I use require not import.. so this does not work with me! const { Button, TelegramClient } = require("telegram");

Wooody82 avatar Dec 25 '21 21:12 Wooody82

Can you try doing this const { Button } = require("telegram/tl/custom/button");

painor avatar Dec 25 '21 21:12 painor

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,
}

Wooody82 avatar Dec 25 '21 21:12 Wooody82

Are you using a bot account? only bots can use buttons

painor avatar Dec 25 '21 21:12 painor

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.

Wooody82 avatar Dec 25 '21 21:12 Wooody82

Thanks works fine with Bot account :-)

 await client.start({
    botAuthToken: "",
  });

https://github.com/gram-js/gramjs/blob/master/examples/main.ts#L40

Wooody82 avatar Dec 25 '21 22:12 Wooody82

how to use button with command

ravindu01manoj avatar Feb 24 '23 13:02 ravindu01manoj