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