Skip to content

Commit

Permalink
support telegram music
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Dec 30, 2024
1 parent fe63b10 commit 20edd5d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/botconn/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ impl TeleTramConnect {
let title = msg_json["title"].as_str().ok_or("title not str")?.to_owned();
let audio = msg_json["audio"].as_str().ok_or("audio not str")?.to_owned();
let image = msg_json["image"].as_str().ok_or("image not str")?;
let content = msg_json["content"].as_str().ok_or("content not str")?;
let url = msg_json["url"].as_str().ok_or("url not str")?;
let content = msg_json["content"].as_str().ok_or("content not str")?.to_owned();
let url = msg_json["url"].as_str().ok_or("url not str")?.to_owned();

let mut form = reqwest::multipart::Form::new();

Expand All @@ -809,24 +809,30 @@ impl TeleTramConnect {
let audio_bin = resp.bytes().await?;
form = form.part(
"audio",
reqwest::multipart::Part::bytes(audio_bin.to_vec()).file_name(title),
reqwest::multipart::Part::bytes(audio_bin.to_vec()).file_name(title.clone()),
)
}

let mut caption = "".to_owned();
if url != "" {
caption.push_str("\n");
caption.push_str(url);
if title != "" {
form = form.part(
"title",
reqwest::multipart::Part::text(title),
);
}

if content != "" {
caption.push_str("\n");
caption.push_str(content);
form = form.part(
"performer",
reqwest::multipart::Part::text(content),
);
}

form = form.part(
"caption",
reqwest::multipart::Part::text(caption.trim().to_owned()),
);
if url != "" {
form = form.part(
"caption",
reqwest::multipart::Part::text(url),
);
}

form = form.part(
"chat_id",
Expand Down

0 comments on commit 20edd5d

Please sign in to comment.