gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.25k stars 178 forks source link

how i can click reply markun button and get the response? #705

Open zarlicho opened 1 month ago

zarlicho commented 1 month ago

i have trying button.click like this client.addEventHandler(async (event) => { if (event.message.buttons != undefined){ console.log(event.message.buttons[1][0].click()) }

and i got this error:

`Promise {

TypeError: Cannot read properties of undefined (reading 'sharePhone') at MessageButton.click (F:\pythonProject\myProject\client dexter\telbot\node_modules\telegram\tl\custom\messageButton.js:70:19) at F:\pythonProject\myProject\client dexter\telbot\test.js:36:47 at _dispatchUpdate (F:\pythonProject\myProject\client dexter\telbot\node_modules\telegram\client\updates.js:144:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) } F:\pythonProject\myProject\client dexter\telbot\node_modules\telegram\tl\custom\messageButton.js:70 async click({ sharePhone = false, shareGeo = [0, 0], password, }) { ^ TypeError: Cannot read properties of undefined (reading 'sharePhone') at MessageButton.click (F:\pythonProject\myProject\client dexter\telbot\node_modules\telegram\tl\custom\messageButton.js:70:19) at F:\pythonProject\myProject\client dexter\telbot\test.js:36:47 at _dispatchUpdate (F:\pythonProject\myProject\client dexter\telbot\node_modules\telegram\client\updates.js:144:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)`
painor commented 1 month ago

try .click({})

MJBlack9000 commented 1 month ago

You might need to get the callback data from the button, and then just directly send that data to the bot. For example, if the button's callback data would be "main_menu_button_data", you'd need to send it like so:

const result = await client.invoke(
    new Api.messages.GetBotCallbackAnswer({
      peer: "botusername",
      msgId: <ID of message that has the button>,
      data: Buffer.from("main_menu_button_data"),
    })
  );

I've not ran this command myself, so I don't know if it will work. But I found it in the docs, and it seems like exactly what you'd need to do: https://gram.js.org/tl/messages/GetBotCallbackAnswer