From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1765823006; bh=gH1s1UHItM5hwLrxMGnGeNIE01Yogy7OZ9ZFKgHu0zA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=TLKs9UrsMQv89ZvzxEyXUcZ28qMvqcrjnQ+wO/eYAnAAfxbfhmumzCylsJLsYlXD1 zLANIVZ8rN7G5qDt9AMA9KxPJx+41SNO6sV1dUVm/goUMkh3w+vWWaQjl7DCwsohYG zf2Tx01zQWzbXVt16z0LTHQh0FmHAy39A5L9Dief3GxdRsqntqYhz368PT3XYsrK8Z 4EOyOIxs0V1UJVPsIIm4lW72Aef3/995w+U5nA8zsb7iGj2F7EN9bfs9yy7sCHTtbm 2FiSz9jX1RWmyuZPZw0T4AwWJmY0utnpOoFG1PT5D5W++d4h82+CiAwpoei7CSmD4F Ji/nYG1p6z6sA== Received: from kanazawa.tail3212ad.ts.net (unknown [125.165.188.218]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 369933204DBD; Mon, 15 Dec 2025 18:23:25 +0000 (UTC) From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 3/4] lib/tgapi: add new properties for type User Date: Tue, 16 Dec 2025 01:23:05 +0700 Message-ID: <20251215182308.48766-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251215182308.48766-1-kiizuha@gnuweeb.org> References: <20251215182308.48766-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Added new properties for type User: - is_premium - can_read_all_group_messages - can_connect_to_business - supports_inline_queries - added_to_attachment_menu - has_main_web_app Fixes typo: - can_join_group -> can_join_groups Oficial documentation says the correct field name of `can_join_groups` is with (s) at the end. This commit also supports `parse_mode`, previously, we cannot use `parse_mode` when sending messages. Now we can use it to format messages with Markdown, MarkdownV2 or HTML. Signed-off-by: Muhammad Rizki --- include/gw/lib/tgapi.h | 28 ++++++++++++++++++++++++++- lib/tgapi.c | 44 +++++++++++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/include/gw/lib/tgapi.h b/include/gw/lib/tgapi.h index 1a35a65..836e329 100644 --- a/include/gw/lib/tgapi.h +++ b/include/gw/lib/tgapi.h @@ -19,14 +19,40 @@ typedef uint64_t time64_t; */ struct tg_user { uint64_t id; + const char *first_name; + + // optional const char *last_name; + + // optional const char *username; + + // optional const char *language_code; + bool is_bot; - bool can_join_group; + + // optional + bool is_premium; + + // optional: only in getMe + bool can_join_groups; + + // optional: only in getMe bool can_read_all_group_messages; + + // optional: only in getMe + bool can_connect_to_business; + + // optional: only in getMe bool supports_inline_queries; + + // optional + bool added_to_attachment_menu; + + // optional: only in getMe + bool has_main_web_app; }; /* diff --git a/lib/tgapi.c b/lib/tgapi.c index 1c3a380..5ecab52 100644 --- a/lib/tgapi.c +++ b/lib/tgapi.c @@ -67,6 +67,27 @@ static int tgj_get_user(struct tg_user *user, json_object *juser) if (json_object_object_get_ex(juser, "is_bot", &res)) user->is_bot = json_object_get_boolean(res) ? true : false; + if (json_object_object_get_ex(juser, "is_premium", &res)) + user->is_premium = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "can_join_groups", &res)) + user->can_join_groups = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "can_read_all_group_messages", &res)) + user->can_read_all_group_messages = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "can_connect_to_business", &res)) + user->can_connect_to_business = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "supports_inline_queries", &res)) + user->supports_inline_queries = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "added_to_attachment_menu", &res)) + user->added_to_attachment_menu = json_object_get_boolean(res) ? true : false; + + if (json_object_object_get_ex(juser, "has_main_web_app", &res)) + user->has_main_web_app = json_object_get_boolean(res) ? true : false; + return 0; } @@ -177,7 +198,7 @@ static int tgj_get_message_entities(struct tg_msg_entity *ent, continue; ent[i].url = json_object_get_string(res); } - + #endif return (int)len; } @@ -232,7 +253,7 @@ static int tgj_arrange_message_variant(struct tg_message *msg, ret = tgj_get_entities_and_alloc(&msg->entities, res); if (unlikely(ret < 0)) return ret; - + msg->entities_len = (size_t)ret; return 0; } @@ -659,11 +680,20 @@ int tgapi_call_send_message(struct tg_api_ctx *ctx, if (!escape_text) return -ENOMEM; - snprintf(url, sizeof(url), - "https://api.telegram.org/bot%s/sendMessage?chat_id=%" PRId64 - "&text=%s&reply_to_message_id=%" PRId64, - ctx->token, call->chat_id, escape_text, - call->reply_to_message_id); + if (call->parse_mode && call->parse_mode[0] != '\0') { + snprintf(url, sizeof(url), + "https://api.telegram.org/bot%s/sendMessage?chat_id=%" PRId64 + "&text=%s&parse_mode=%s&reply_to_message_id=%" PRId64, + ctx->token, call->chat_id, escape_text, + call->parse_mode, call->reply_to_message_id); + } else { + snprintf(url, sizeof(url), + "https://api.telegram.org/bot%s/sendMessage?chat_id=%" PRId64 + "&text=%s&reply_to_message_id=%" PRId64, + ctx->token, call->chat_id, escape_text, + call->reply_to_message_id); + } + curl_free(escape_text); printf("Curl to URL: %s\n", url); -- Muhammad Rizki