aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-06-26 19:33:37 +0300
committerlevlam <levlam@telegram.org>2026-06-26 19:33:37 +0300
commit534a408e9c60d9b03c5ebe18a8d5b57bd4992a25 (patch)
tree50eeff13e78f1f97da9e59c7e5fc962ee28d59fe
parentd46f319ac100701d19454797dd8cd8f87b122152 (diff)
Add td_api::createRichMessageWithAi.
-rw-r--r--td/generate/scheme/td_api.tl10
-rw-r--r--td/telegram/Requests.cpp9
-rw-r--r--td/telegram/Requests.h2
-rw-r--r--td/telegram/TranslationManager.cpp7
-rw-r--r--td/telegram/TranslationManager.h3
-rw-r--r--td/telegram/cli.cpp6
6 files changed, 35 insertions, 2 deletions
diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl
index 289f3cae1..ddfdd4cf7 100644
--- a/td/generate/scheme/td_api.tl
+++ b/td/generate/scheme/td_api.tl
@@ -11941,7 +11941,7 @@ summarizeMessage chat_id:int53 message_id:int53 translate_to_language_code:strin
//@add_emojis Pass true to add emoji to the text
composeTextWithAi text:formattedText translate_to_language_code:string style_name:string add_emojis:Bool = FormattedText;
-//@description Changes rich messages using an AI model. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
+//@description Changes a rich message using an AI model. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
//@message The original message
//@translate_to_language_code Pass a language code to which the text will be translated; pass an empty string if translation isn't needed. See translateText.to_language_code for the list of supported values
//@style_name Name of the style of the resulted text; handle updateTextCompositionStyles to get the list of supported styles; pass an empty string to keep the current style of the text or if a custom prompt is used
@@ -11949,11 +11949,17 @@ composeTextWithAi text:formattedText translate_to_language_code:string style_nam
//@add_emojis Pass true to add emoji to the text
composeRichMessageWithAi message:inputRichMessage translate_to_language_code:string style_name:string custom_prompt:string add_emojis:Bool = RichMessage;
+//@description Creates a new rich message using an AI model. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
+//@prompt Prompt that will be used to create the message; 0-getOption("text_composition_style_prompt_length_max") characters
+//@language_code Pass a language code in which the text will be created
+//@add_emojis Pass true to add emoji to the text
+createRichMessageWithAi prompt:string language_code:string add_emojis:Bool = RichMessage;
+
//@description Fixes text using an AI model; must not be used in secret chats. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
//@text The original text
fixTextWithAi text:formattedText = FixedText;
-//@description Fixes rich message using an AI model. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
+//@description Fixes a rich message using an AI model. May return an error with a message "AICOMPOSE_FLOOD_PREMIUM" if Telegram Premium is required to send further requests
//@message The original message
fixRichMessageWithAi message:inputRichMessage = RichMessage;
diff --git a/td/telegram/Requests.cpp b/td/telegram/Requests.cpp
index 059948e53..3b06ad7da 100644
--- a/td/telegram/Requests.cpp
+++ b/td/telegram/Requests.cpp
@@ -2901,6 +2901,15 @@ void Requests::on_request(uint64 id, td_api::composeRichMessageWithAi &request)
request.add_emojis_, std::move(promise));
}
+void Requests::on_request(uint64 id, td_api::createRichMessageWithAi &request) {
+ CHECK_IS_USER();
+ CLEAN_INPUT_STRING(request.language_code_);
+ CLEAN_INPUT_STRING(request.prompt_);
+ CREATE_REQUEST_PROMISE();
+ td_->translation_manager_->create_rich_message_with_ai(request.prompt_, request.language_code_, request.add_emojis_,
+ std::move(promise));
+}
+
void Requests::on_request(uint64 id, td_api::fixTextWithAi &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
diff --git a/td/telegram/Requests.h b/td/telegram/Requests.h
index 49afc1d8a..a2933b8fa 100644
--- a/td/telegram/Requests.h
+++ b/td/telegram/Requests.h
@@ -350,6 +350,8 @@ class Requests {
void on_request(uint64 id, td_api::composeRichMessageWithAi &request);
+ void on_request(uint64 id, td_api::createRichMessageWithAi &request);
+
void on_request(uint64 id, td_api::fixTextWithAi &request);
void on_request(uint64 id, td_api::fixRichMessageWithAi &request);
diff --git a/td/telegram/TranslationManager.cpp b/td/telegram/TranslationManager.cpp
index 51e24f3c5..f8cfae9c0 100644
--- a/td/telegram/TranslationManager.cpp
+++ b/td/telegram/TranslationManager.cpp
@@ -700,6 +700,13 @@ void TranslationManager::compose_rich_message_with_ai(td_api::object_ptr<td_api:
->send(true, input_rich_message, translate_to_language_code, std::move(input_tone), emojify, false);
}
+void TranslationManager::create_rich_message_with_ai(const string &prompt, const string &language_code, bool emojify,
+ Promise<td_api::object_ptr<td_api::richMessage>> &&promise) {
+ td_->create_handler<ComposeRichMessageWithAiQuery>(std::move(promise))
+ ->send(false, InputRichMessage(), language_code,
+ telegram_api::make_object<telegram_api::inputAiComposeToneSingleUse>(prompt), emojify, false);
+}
+
void TranslationManager::proofread_rich_message_with_ai(td_api::object_ptr<td_api::inputRichMessage> &&message,
Promise<td_api::object_ptr<td_api::richMessage>> &&promise) {
TRY_RESULT_PROMISE(promise, input_rich_message, get_input_rich_message(std::move(message)));
diff --git a/td/telegram/TranslationManager.h b/td/telegram/TranslationManager.h
index e253896cd..64d027a62 100644
--- a/td/telegram/TranslationManager.h
+++ b/td/telegram/TranslationManager.h
@@ -63,6 +63,9 @@ class TranslationManager final : public Actor {
const string &custom_prompt, bool emojify,
Promise<td_api::object_ptr<td_api::richMessage>> &&promise);
+ void create_rich_message_with_ai(const string &prompt, const string &language_code, bool emojify,
+ Promise<td_api::object_ptr<td_api::richMessage>> &&promise);
+
void proofread_message_with_ai(td_api::object_ptr<td_api::formattedText> &&text,
Promise<td_api::object_ptr<td_api::fixedText>> &&promise);
diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp
index 721342013..aa4893bc4 100644
--- a/td/telegram/cli.cpp
+++ b/td/telegram/cli.cpp
@@ -5239,6 +5239,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::composeRichMessageWithAi>(
as_input_rich_message(message), to_language_code, style_name, op == "crmwac" ? "Make text uppercase" : "",
emojify));
+ } else if (op == "cnrmwa") {
+ string language_code;
+ bool emojify;
+ string prompt;
+ get_args(args, language_code, emojify, prompt);
+ send_request(td_api::make_object<td_api::createRichMessageWithAi>(prompt, language_code, emojify));
} else if (op == "ftwa") {
string text;
get_args(args, text);