diff --git a/include/telebot-core.h b/include/telebot-core.h index cec6ef2..220929d 100644 --- a/include/telebot-core.h +++ b/include/telebot-core.h @@ -1199,6 +1199,27 @@ telebot_error_e telebot_core_delete_message(telebot_core_handler_t *core_h, */ void telebot_core_put_response(telebot_core_response_t *response); +/** + * @brief Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. + * @param[in] core_h The telebot core handler created with #telebot_core_create(). + * @param[in] short_description New short description for the bot; 0-120 characters. + * @param[out] response Response data that contains "True" on success. + * It MUST be freed with #telebot_core_put_response(). + * @return on Success, TELEBOT_ERROR_NONE is returned, otherwise a negative error value. + */ +telebot_error_e telebot_core_set_my_short_description(telebot_core_handler_t *core_h, + const char *short_description, + telebot_core_response_t *response); + +/** + * @brief Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success. + * @param[in] core_h The telebot core handler created with #telebot_core_create(). + * @param[out] response Response data, MUST be freed with #telebot_core_put_response(). + * @return on Success, TELEBOT_ERROR_NONE is returned, otherwise a negative error value. + */ +telebot_error_e telebot_core_get_my_short_description(telebot_core_handler_t *core_h, + telebot_core_response_t *response); + /** * @} // end of APIs */ diff --git a/include/telebot-methods.h b/include/telebot-methods.h index 7a7e90e..898a50a 100644 --- a/include/telebot-methods.h +++ b/include/telebot-methods.h @@ -881,6 +881,7 @@ telebot_error_e telebot_set_chat_title(telebot_handler_t handle, long long int c telebot_error_e telebot_set_chat_description(telebot_handler_t handle, long long int chat_id, const char *description); + /** * @brief Pin a message in a supergroup or a channel. The bot must be an administrator * in the chat for this to work and must have the 'can_pin_messages' admin right @@ -1180,6 +1181,31 @@ telebot_error_e telebot_stop_poll(telebot_handler_t handle, long long int chat_i telebot_error_e telebot_delete_message(telebot_handler_t handle, long long int chat_id, int message_id); + +//////////////////////////////////////////////////////////////////////////////////////// +//ozlb +//////////////////////////////////////////////////////////////////////////////////////// + +/** + * @brief Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. + * @param[in] handle The telebot handler created with #telebot_create(). + * @param[in] short_description New chat description, 0-120 characters. + * @return on Success, #TELEBOT_ERROR_NONE is returned, otherwise a negative + * error value. + */ +telebot_error_e telebot_set_my_short_description(telebot_handler_t handle, + const char *short_description); + +/** + * @brief Use this method to get the current bot description for the given user language. Returns BotDescription on success. + * + * @param[in] handle The telebot handler created with #telebot_create(). + * @param[out] short_description String The bot's short description + * @return on Success, #TELEBOT_ERROR_NONE is returned, and user object is + * stored in input parameter. + */ +telebot_error_e telebot_get_my_short_description(telebot_handler_t handle, char **short_description); + /** * @} // end of APIs */ diff --git a/include/telebot-private.h b/include/telebot-private.h index b3748e0..dd59d7b 100644 --- a/include/telebot-private.h +++ b/include/telebot-private.h @@ -84,6 +84,9 @@ #define TELEBOT_METHOD_EDIT_MESSAGE_REPLY_MARKUP "editMessageReplyMarkup" #define TELEBOT_METHOD_STOP_POLL "stopPoll" #define TELEBOT_METHOD_DELETE_MESSAGE "deleteMessage" +//ozlb +#define TELEBOT_METHOD_SET_MY_SHORT_DESCRIPTION "setMyShortDescription" +#define TELEBOT_METHOD_GET_MY_SHORT_DESCRIPTION "getMyShortDescription" #ifdef DEBUG #define ERR(fmt, args...) fprintf(stderr, "[ERROR][%s:%d]" fmt "\n", __func__, __LINE__, ##args) diff --git a/src/telebot-core.c b/src/telebot-core.c index 19292a8..0c1150f 100644 --- a/src/telebot-core.c +++ b/src/telebot-core.c @@ -2628,3 +2628,44 @@ telebot_error_e telebot_core_delete_message(telebot_core_handler_t *core_h, return telebot_core_curl_perform(core_h, TELEBOT_METHOD_DELETE_MESSAGE, mimes, index, response); } + +//////////////////////////////////////////////////////////////////////////////////////// +//ozlb +//////////////////////////////////////////////////////////////////////////////////////// + +telebot_error_e telebot_core_set_my_short_description(telebot_core_handler_t *core_h, + const char *short_description, telebot_core_response_t *response) +{ + if ((core_h == NULL) || (core_h->token == NULL)) + { + ERR("Handler, or token is NULL"); + return TELEBOT_ERROR_INVALID_PARAMETER; + } + + if ((short_description == NULL) || (strlen(short_description) > 120)) + { + ERR("Valid title is required"); + return TELEBOT_ERROR_INVALID_PARAMETER; + } + + int index = 0; + telebot_core_mime_t mimes[1]; // number of arguments + mimes[index].name = "short_description"; + mimes[index].type = TELEBOT_MIME_TYPE_DATA; + snprintf(mimes[index].data, sizeof(mimes[index].data), "%s", short_description); + ++index; + + return telebot_core_curl_perform(core_h, TELEBOT_METHOD_SET_MY_SHORT_DESCRIPTION, mimes, index, response); +} + +telebot_error_e telebot_core_get_my_short_description(telebot_core_handler_t *core_h, + telebot_core_response_t *response) +{ + if ((core_h == NULL) || (core_h->token == NULL)) + { + ERR("Handler or token is NULL"); + return TELEBOT_ERROR_INVALID_PARAMETER; + } + + return telebot_core_curl_perform(core_h, TELEBOT_METHOD_GET_MY_SHORT_DESCRIPTION, NULL, 0, response); +} diff --git a/src/telebot.c b/src/telebot.c index 37ede1e..aaa940b 100644 --- a/src/telebot.c +++ b/src/telebot.c @@ -25,10 +25,10 @@ #include #include #include -#include -#include -#include -#include +#include "telebot.h" +#include "telebot-core.h" +#include "telebot-private.h" +#include "telebot-parser.h" typedef struct telebot_handler_s { @@ -1967,3 +1967,79 @@ static void telebot_put_callback_query(telebot_callback_query_t *query) //TODO: static void telebot_put_invoice(telebot_invoice_t *invoice); //TODO: static void telebot_put_payment(telebot_successful_payment_t *payment); //TODO: static void telebot_put_game(telebot_game_t *game); + +telebot_error_e telebot_set_my_short_description(telebot_handler_t handle, + const char *short_description) +{ + telebot_hdata_t *_handle = (telebot_hdata_t *)handle; + if (_handle == NULL) + return TELEBOT_ERROR_NOT_SUPPORTED; + + if (short_description == NULL) + return TELEBOT_ERROR_INVALID_PARAMETER; + + telebot_core_response_t response; + int ret = telebot_core_set_my_short_description(_handle->core_h, short_description, + &response); + telebot_core_put_response(&response); + + return ret; +} + +telebot_error_e telebot_get_my_short_description(telebot_handler_t handle, char **short_description) +{ + telebot_hdata_t *_handle = (telebot_hdata_t *)handle; + if (_handle == NULL) + return TELEBOT_ERROR_NOT_SUPPORTED; + + if (short_description == NULL) + return TELEBOT_ERROR_INVALID_PARAMETER; + + *short_description = NULL; + + telebot_core_response_t response; + int ret = telebot_core_get_my_short_description(_handle->core_h, &response); + if (ret != TELEBOT_ERROR_NONE) + return ret; + + struct json_object *obj = telebot_parser_str_to_obj(response.data); + if (obj == NULL) + { + ret = TELEBOT_ERROR_OPERATION_FAILED; + goto finish; + } + + struct json_object *ok = NULL; + if (!json_object_object_get_ex(obj, "ok", &ok) || !json_object_get_boolean(ok)) + { + ret = TELEBOT_ERROR_OPERATION_FAILED; + goto finish; + } + + struct json_object *result = NULL; + if (!json_object_object_get_ex(obj, "result", &result)) + { + ret = TELEBOT_ERROR_OPERATION_FAILED; + goto finish; + } + + struct json_object *j_short_description = NULL; + if (json_object_object_get_ex(result, "short_description", &j_short_description)) + { + *short_description = TELEBOT_SAFE_STRDUP(json_object_get_string(j_short_description)); + if (*short_description == NULL) + ret = TELEBOT_ERROR_OUT_OF_MEMORY; + else + ret = TELEBOT_ERROR_NONE; + } + else + { + ret = TELEBOT_ERROR_OPERATION_FAILED; + } + +finish: + if (obj) json_object_put(obj); + telebot_core_put_response(&response); + + return ret; +}