From 7e14e8f9e7769cd328924a60770a510c3032736a Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 5 Sep 2019 19:11:16 +0300 Subject: [PATCH] Fix redundant `""` when sending messages (Note: string types should use `FormBuilder::add_raw` instead of `FormBuiolder::add`) --- src/core/requests/form_builder.rs | 11 +++++++++++ src/core/requests/send_message.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/requests/form_builder.rs b/src/core/requests/form_builder.rs index e27f1d04..5074e52d 100644 --- a/src/core/requests/form_builder.rs +++ b/src/core/requests/form_builder.rs @@ -45,6 +45,17 @@ impl FormBuilder { } } + /// Add the supplied key-value pair to this `FormBuilder`. + /// With raw str value, so `serde_json` will not add redundant `""` + pub fn add_raw(self, name: &str, value: &str) -> Self { + Self { + form: self.form.text( + name.to_owned(), + value.to_owned(), + ), + } + } + pub fn build(self) -> Form { self.form } diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index 41f441a5..c5bff10f 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -25,7 +25,7 @@ impl<'a> Request<'a> for SendMessage<'a> { Box::pin(async move { let params = FormBuilder::new() .add("chat_id", &self.chat_id) - .add("text", &self.text) + .add_raw("text", &self.text) .add_if_some("parse_mode", self.parse_mode.as_ref()) .add_if_some( "disable_web_page_preview",