如何通过Curl发送多个文件(如.txt)到Telegram

8dtrkrch  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(65)

我试图通过 curl 发送多个消息,如两个文本文件到电报.它的工作正常,如果它只是一个Txt文件,但如果我想发送两个Txt文件,它会不工作.我也试过这件事,但不工作:

curl -X POST -F "chat_id=-CHAT_ID" \
     -F "document=@/tmp/test/1.txt" \
     -F "document=@/tmp/test/2.txt" \
     https://api.telegram.org/API_TOKEN/sendDocument

字符串
该命令工作正常,没有任何错误,但只有第一个Txt文件被发送。没有第二个Txt文件。有什么想法吗?谢谢你的帮助。

6xfqseft

6xfqseft1#

sendDocument只能发送一个文件。
您需要使用sendMediaGroup通过一个CURL命令发送多个文件。
然后以multipart/form-data的形式传递数据,格式如下:

[{ "type": "document", "media": "attach://file1" }, ...]

字符串
有关更多信息,请阅读inputMediaDocument文档。
所以一个curl命令的例子看起来像:

curl -F "chat_id=13245679" \
     -F 'media=[{"type": "document", "media": "attach://file1"}, {"type": "document", "media": "attach://file2" }]' \
     -F "file1=@/tmp/test1.txt" \
     -F "file2=@/tmp/test2.txt" \
     "https://api.telegram.org/bot<BOT-TOKEN>/sendMediaGroup"


这将导致一个包含这两个文件的mediaGroup:
x1c 0d1x的数据

相关问题