rizaumami / tdbot.lua

Lua wrapper for telegram-bot
GNU General Public License v3.0
24 stars 21 forks source link

How to send inline keyboard button via "replyMarkupInlineKeyboard" in bot (API) mode #14

Closed realsamanrad closed 5 years ago

realsamanrad commented 6 years ago

Hi, Can you give an example that explain how to send inline keyboard button via "replyMarkupInlineKeyboard" (on sendMessage method) in bot (API) mode ?

The new update of tdlib supports API, so it should work.

I use the code below, but it returns error that says: [ 1][t 0][1533544806.054300547][clilua.cpp:148][!Td] FAILED TO PARSE LUA: [Error : 0 : Expected array, got JsonObject] [ 0][t 0][1533496321.609632015][clilua.cpp:186][!Td] lua: ./bot.lua:51: assertion failed!

function tdbot_update_callback (data)
  if (data["@type"]== "updateNewMessage") then
    local msg = data.message
    if msg.content["@type"]== "messageText" then
      if msg.content.text.text == "ping" then
        assert(tdbot_function({
          ["@type"]="sendMessage",
          chat_id=msg.chat_id,
          reply_to_message_id=msg.id,
          disable_notification=false,
          from_background=true,
          reply_markup={
            ["@type"]="replyMarkupInlineKeyboard",
            rows={
              {
                text="example",
                type={
                  ["@type"]="inlineKeyboardButtonTypeUrl",
                  url="https://example.com"
                }
              }
            }
          },
          input_message_content={
            ["@type"]="inputMessageText",
            text={text="pong"},
            disable_web_page_preview=true,
            clear_draft=false,
            entities={},
            parse_mode=nil
          }
        },dl_cb, nil))
      end
    end
  end
end

So what's the problem?! Tnx

realsamanrad commented 6 years ago

Problem solved, just edited the code like this:

reply_markup={
            ["@type"]="replyMarkupInlineKeyboard",
            rows={
                [0]={
                    [0]={
                        text="example",
                        type={
                          ["@type"]="inlineKeyboardButtonTypeUrl",
                          url="https://example.com"
                        }
                    }
                }
            }
          }