0
我需要純perl的(沒有WWW ::電報:: BotAPI)實現sendPhoto BotAPI方法的幫助Perl |電報博特和sendPhoto方法
簡單的文本我沒有問題發送
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON::MaybeXS;
....
....
my $ua = LWP::UserAgent->new;
utf8::decode($message);
my $p = {
chat_id=>$groupid,
parse_mode=>'HTML',
text=>$message
};
my $response = $ua->request(
POST 'https://api.telegram.org/bot'.$token.'/sendMessage',
Content_Type => 'application/json',
Content => JSON::MaybeXS::encode_json($p)
);
...
但隨着sendPhoto (https://core.telegram.org/bots/api#sendphoto)我有問題。如果我想上傳新圖片,我必須將哪個JSON發送到服務器?
chat_id=>$groupid,
caption=>$message
photo=> { ? binary blob here ? }
嗯有效。文檔說,InputFile對象應該使用multipart/formdata發佈。但這很奇怪。 – simbabque
不使用WWW ::電報:: BotAPI不包括[來源]的借用(https://v1.metacpan.org/source/ROBERTOF/WWW-Telegram-BotAPI-0.07/lib/WWW/Telegram/BotAPI .pm的#L80)。我建議你研究它是如何在那裏完成的。看起來你需要切換內容類型。作者非常好,甚至可以在源代碼中使用HTTP :: Request :: Common來創建鏈接。一般來說,消息來源具有娛樂性,值得一讀。 – simbabque
請問你爲什麼不想使用模塊? – Borodin