python-botogram/botogram

Button callback won't work

Closed this issue · 9 comments

BJ4K3 commented

Hi, I'm trying to send to user a message with buttons, naturally followed by a callback, the button code work properly but the callback won't work at all.
Here's the code:

@bot.command("remove")
def remove(chat, message, args):
    btns = botogram.Buttons()
    btns[0].callback("YES", "rem", "54GBfd")
    chat.send("Are you sure?", attach=btns)

@bot.callback("rem")
def rem(query, data, chat, message):
    message.delete()
    query.notify("Removed")

As already said the button is visualized but when I click on it, the button starts loading and below the Bot name appears: "Connecting...".

@BJ4K3 Hi, thanks for your issue!
It seems like a networking problem, have you tried with an another client or with a more stable internet connection?

BJ4K3 commented

Thank you for the answer. My connection is quite stable, I don't think that the problem is it.
Can you provide me a working (that work for you) code with button and callback, please?

Your code seems fine, but if you want an official example you can see this page. Which developing platform are you using (Windows, macOS, GNU/Linux, ...)? Other parts of the bot are working fine?

BJ4K3 commented

I'm developing on Windows on VS Code. The others parts are working fine.

BJ4K3 commented

I tried to write into terminal "print()" a message when callback is fired, but nothing happens.

Try to set env variable BOTOGRAM_DEBUG to 1 and post the logs, thanks.

BJ4K3 commented

This is the log:

12:31.18 -   DEBUG   - Component botogram just loaded into the bot
12:31.18 -   DEBUG   - Component botogram just loaded into the bot
12:31.18 -   DEBUG   - Component botogram just loaded into the bot
12:31.18 -   DEBUG   - Worker process is ready! (pid: 12292)
12:31.18 -   DEBUG   - Received IPC command jobs.get
12:31.18 -   DEBUG   - Worker process is ready! (pid: 7508)
12:31.18 -   DEBUG   - Received IPC command jobs.get
12:31.18 -   DEBUG   - Updater process is ready! (pid: 7484)
12:31.34 -   DEBUG   - Received IPC command jobs.bulk_put
12:31.34 -   DEBUG   - Processing update #888665245 with the hook Component::remove...
12:31.34 -   DEBUG   - Update #888665245 was just processed by the Component::remove hook.
12:31.34 -   DEBUG   - Received IPC command jobs.get
12:31.39 -   DEBUG   - Received IPC command jobs.bulk_put
12:31.39 -   DEBUG   - Processing update #888665246 with the hook Component::rem
12:31.39 -   DEBUG   - No hook actually processed the #888665246 update.        
12:31.39 -   DEBUG   - Received IPC command jobs.get

this is the code i just used:

import botogram
import os

os.environ['BOTOGRAM_DEBUG'] = '1'
bot = botogram.create("API-KEY")

@bot.command("remove")
def remove(chat, message, args):
    btns = botogram.Buttons()
    btns[0].callback("TEST", "rem")
    chat.send("TEST", attach=btns)

@bot.callback("rem")
def rem(query, data, chat, message):
    print("OK")
    message.delete()
    query.notify("Removed")

if __name__ == '__main__':
    bot.run()
BJ4K3 commented

Ok, I understood the problem. I was using python2.7, in python3 the problem doesn't exist. I started the same code in python3, after downloading all packages, it works properly.

👍