Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capiton are json encoded even when not send as json #6

Closed
neodc opened this issue Jan 29, 2022 · 3 comments
Closed

Capiton are json encoded even when not send as json #6

neodc opened this issue Jan 29, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@neodc
Copy link

neodc commented Jan 29, 2022

Hello,

When I try to send a file with a caption it is surrounded by " and if it contain the character " it is send as \".

Here a minimal example:

use telbot_ureq::types::message::SendDocument;
use telbot_ureq::types::chat::ChatId;
use telbot_ureq::types::file::InputFile;
use telbot_ureq::Api;

fn main() {
	let data: Vec<u8> = "exemple".to_string().into_bytes();
	let caption = "exemple \" exemple";

	let api = Api::new("...".to_string());
	let chat_id: ChatId = 123456789i64.into();

	let file = InputFile {
		name: "test.txt".to_string(),
		data: data,
		mime: "text/plain".to_string(),
	};

	api
		.send_file(
			&SendDocument::new(chat_id, file)
				.with_caption(caption)
		)
		.expect("Error while sending document to Telegram");
}

And here what I get in Telegram:

image

From what I can see the problem is that the send_file method use serde_json::to_value but the body is not send as json (but as multipart) so the text is json escaped but Telegram do not decode it.

PS: I'm using the main version from git telbot-ureq = { git = "https://github.com/kiwiyou/telbot" }

@kiwiyou
Copy link
Owner

kiwiyou commented Jan 29, 2022

Fixed in main branch. Thanks!

@kiwiyou kiwiyou closed this as completed Jan 29, 2022
@neodc
Copy link
Author

neodc commented Mar 10, 2022

Thanks again for the quick fix, do you think you could release it in a 0.3.1 version ?

@kiwiyou
Copy link
Owner

kiwiyou commented Mar 13, 2022

@neodc Published telbot-ureq 0.3.1 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants