shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
147 stars 34 forks source link

Inline Keyboard example is not working #31

Closed ElVasquito closed 4 years ago

ElVasquito commented 4 years ago

Hello, I am trying to run the Inline Keyboard example, and this is the Serial output:

--- Cut --- Starting TelegramBot...

testConnection OK

Exception (28): epc1=0x4020caef epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000002 depc=0x00000000

stack>>>

ctx: cont sp: 3ffffd40 end: 3fffffc0 offset: 01a0 3ffffee0: 00000000 00000008 00000008 40209bcc
3ffffef0: 3fffff30 3fffff3c 3fffff30 3ffe8a24
3fffff00: 3ffefa74 3fffff80 3ffeed0c 40203a7f
3fffff10: 3ffefa74 3fffff8c 3ffeed0c 00000002
3fffff20: 3ffefa74 3fffff8c 3ffeed0c 40203b98
3fffff30: 00000000 00000000 ff004e4f 00000000
3fffff40: 00000000 ff000000 3fffff80 40207930
3fffff50: 3fffff80 3ffefa74 3fffff80 40207970
3fffff60: 3ffe8604 00000001 00000002 3ffeee28
3fffff70: 3fffdad0 3ffeed2c 3ffeed0c 4020113b
3fffff80: 6867696c 004e4f74 00efeffe 4847494c
3fffff90: 30322554 00004e4f feefeffe feefeffe
3fffffa0: feefeffe 00000000 3ffeedf8 40208050
3fffffb0: feefeffe feefeffe 3ffe8554 4010051d
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v8b899c12 ~ld Starting TelegramBot... [Repeats over] --- Cut ---

How to debug this?

ElVasquito commented 4 years ago

I checked a bit more, and the crash occurs at function CTBotInlineKeyboard::addButton() in CTBotInlineKeyboard.cpp At line 47, here: button["callback_data"] = command; Any clues?

shurillu commented 4 years ago

Hello ElVasquito, very weird behavior, i checked it! Try downgrading the library version (1.3.1) while I'm looking for the bug. Thanks for the issue notification.

Stefano

shurillu commented 4 years ago

Hello ElVasquito, I found the bug and now in the master branch there is a version that fix it: please check it and let me know. Soon a new release.

Stefano

ElVasquito commented 4 years ago

Yes, it works now!!! Thank you very much, Stefano!!!!! Although I don't know what changed these days because the buttons were previously showing under the reply bar, and now they do on the chat itself... Also happens on the buttons of the botFather... Oh well, maybe Telegram changed that just recently, or I am missing something... If it's no much trouble for you, can you tell me how can I add the optional request_contact flag to a button? And also one more little question: the replies from the library are taking 8-15 seconds each, and the botFather replies instantly, is this due to the limited speed of the ESP8266? I tried overclocking to 160MHz but I saw no improvement, on what depends? TIA

ElVasquito commented 4 years ago

Ok, been experimenting a bit more, and I will answer my own questions. The keyboard I was looking for was just "keyboard" and not "inline_keyboard", so what I did (correct me if I'm wrong) was duplicating CTBotInlineKeyboard.cpp as CTBotKeyboard.cpp, and renaming all references of CTBotInlineKeyboard to CTBotKeyboard on it, and on initialize() I just changed "inline_keyboard" to plain "keyboard". The addButton function ended up like this: ` bool CTBotKeyboard::addButton(String text, bool request_contact) { JsonObject& button = m_buttons->createNestedObject(); text = URLEncodeMessage(text); button["text"] = text; button["request_contact"] = request_contact;

if (m_isRowEmpty)
    m_isRowEmpty = false;
return(true);

} ` So now I got a working keyboard underneath the reply bar, and I can request_contact through it. Awesome! I'm pretty sure there should be a "cleaner" way of doing this instead of duplicating everything, but oh well, it works :) So the only question remaining is the one about the delay in the replies, can it get a little better somehow?

shurillu commented 4 years ago

Hello ElVasquito, very good work! I'm thinking on how integrate the others keyboards in order to get those functionalities (without duplicate classes). BTW, in the master branch I fixed the delay ;-) Cheers,

Stefano

ElVasquito commented 4 years ago

OH MY, Stefano!!!!!!!!!!!!!!!!!!!!!!!! You got it down to 4 seconds for most replies!!!!!!! 7 in the worst case, rarely!! And removing the delay(500) at the end even 3 secs!!!! YOU DID SOME MAGIC THERE!!! Although I fear of being banned from Telegram by polling updates continually 24/7 without the delay. An idea would be to poll every 10 seconds and once a message is received, remove the delay for like a minute, until no new messages are received ;) Awesome work, pal!! Keep it up!!! If things get better down here, I will definitely make a donation in the near future to support you!!!! THANK YOU!!!!!!!!!!!!!!!!