improve keyboard api

This commit is contained in:
2025-05-21 17:20:52 +02:00
parent b2592d7334
commit 35ca1f0eee
9 changed files with 93 additions and 79 deletions

View File

@@ -4,6 +4,6 @@
#include "types.h"
#include <json-c/json.h>
json_object *tgbot_new_inlinekeyboardmarkup(tgbot_inlinekeyboardmarkup **keyboard, size_t rows, size_t columns);
json_object *tgbot_new_inlinekeyboardmarkup(tgbot_inlinekeyboard *keyboard);
#endif

View File

@@ -14,9 +14,9 @@ tgbot_rc tgbot_request(tgbot *bot, char *url, struct memory_buffer **mb, json_ob
/* Methods */
tgbot_rc tgbot_get_me(tgbot *bot, tgbot_me *me);
tgbot_rc tgbot_send_message(tgbot *bot, int64_t chat_id, char *text, char *parse_mode, tgbot_inlinekeyboardmarkup **reply_markup, size_t rows, size_t columns);
tgbot_rc tgbot_send_message(tgbot *bot, int64_t chat_id, char *text, char *parse_mode, tgbot_inlinekeyboard *reply_markup);
/* Updating Methods */
tgbot_rc tgbot_edit_message_text(tgbot *bot, int64_t chat_id, long message_id, char *text, tgbot_inlinekeyboardmarkup **keyboard, size_t rows, size_t columns);
tgbot_rc tgbot_edit_message_text(tgbot *bot, int64_t chat_id, long message_id, char *text, tgbot_inlinekeyboard *keyboard);
#endif

View File

@@ -4,17 +4,25 @@
#include "common.h"
/**
* A structure to represent InlineKeyboardMarkup
* A structure to represent keyboard's buttons
*/
struct tgbot_inlinekeyboardmarkup_t {
struct tgbot_inlinekeyboardbutton_t {
char text[200]; /**< If this field is empty the button will be skipped */
char url[200]; /**< (Optional) URL of the button */
char callback_data[64]; /**< Callback data */
};
typedef struct tgbot_inlinekeyboardmarkup_t tgbot_inlinekeyboardmarkup;
typedef struct tgbot_inlinekeyboardbutton_t tgbot_inlinekeyboardbutton;
tgbot_rc
tgbot_allocate_inlinekeyboardmarkup(tgbot_inlinekeyboardmarkup ***keyboard, size_t rows, size_t columns);
tgbot_rc tgbot_deallocate_inlinekeyboardmarkup(tgbot_inlinekeyboardmarkup **keyboard, size_t rows);
struct tgbot_inlinekeyboard_t {
size_t rows;
size_t columns;
struct tgbot_inlinekeyboardbutton_t *buttons;
};
typedef struct tgbot_inlinekeyboard_t tgbot_inlinekeyboard;
tgbot_inlinekeyboard *tgbot_new_inlinekeyboard(size_t rows, size_t columns);
tgbot_rc tgbot_inlinekeyboard_button(tgbot_inlinekeyboard *keyboard, size_t row, size_t column, const char *text, const char *url, const char *callback_data);
tgbot_inlinekeyboardbutton *tgbot_inlinekeyboard_button_at(tgbot_inlinekeyboard *keyboard, size_t row, size_t column);
void tgbot_destroy_inlinekeyboard(tgbot_inlinekeyboard *keyboard);
#endif