inline_keyboard.lua

-- https://core.telegram.org/bots/2-0-intro#new-inline-keyboards

local json_encode = (util or require("gmod.util")).TableToJSON
local ggram = require("ggram")

local bot = ggram("123456789:QWERTYUIOPASDFGHJKLZXCVBNM")
require("ggram.polling").start(bot)

bot.command("start", function(ctx)
	ctx.reply.inlineKeyboard({
		{
			{text = "Line 1, row 1", callback_data = "any"},
			{text = "Line 1, row 2", url = "https://example.com"}
		},
		{
			{text = "Line 2, row 1", callback_data = "any2"}
		}
	}).text("Hello world!")
end)


bot.callback(function(ctx)
	local query = ctx.callback_query
	if query.data == "any" then
		ctx.answer({text = "It's inline answer"})

	else
		ctx.reply.text("You just pressed button in second row. ctx.update:"):next(function()
			return ctx.reply.markdown("```\n" .. json_encode(ctx.update, true) .. "\n```")
		end):next(function()
			return ctx.reply.text("Json payload above 👆")
		end):next(function()
			return ctx.reply.text("The third message")
		end)
	end
end, "callback_example")

ggram.idle()
generated by LDoc 1.5.0 Last updated 2024-09-04 21:00:44