From: Muhammad Rizki <kiizuha@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Muhammad Rizki <kiizuha@gnuweeb.org>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH v1 3/4] lib/tgapi: add new properties for type User
Date: Tue, 16 Dec 2025 01:23:05 +0700 [thread overview]
Message-ID: <20251215182308.48766-4-kiizuha@gnuweeb.org> (raw)
In-Reply-To: <20251215182308.48766-1-kiizuha@gnuweeb.org>
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 <kiizuha@gnuweeb.org>
---
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
next prev parent reply other threads:[~2025-12-15 18:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 18:23 [PATCH v1 0/4] GNUWeebBot2 Fixes and New Updates Muhammad Rizki
2025-12-15 18:23 ` [PATCH v1 1/4] .vscode: add some C/C++ extension settings Muhammad Rizki
2025-12-15 18:23 ` [PATCH v1 2/4] core:lib: fix memory leak and reduce threads Muhammad Rizki
2025-12-15 18:23 ` Muhammad Rizki [this message]
2025-12-15 18:23 ` [PATCH v1 4/4] modules: create a `user` module Muhammad Rizki
2025-12-18 22:16 ` [PATCH v1 0/4] GNUWeebBot2 Fixes and New Updates Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251215182308.48766-4-kiizuha@gnuweeb.org \
--to=kiizuha@gnuweeb.org \
--cc=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox