Telegram 机器人 sendVoice() returns 总是 "wrong file identifier"

Telegram bot sendVoice() returns always "wrong file identifier"

我正在尝试从 Telegram BOT 发送语音消息,但没有成功。

作为概念证明,我正在尝试使用 curl:

#!/bin/bash
TOKEN=$(cat .token)
CHAT=$(cat .chat)
URL="http://server2.mbrt.it:8080/static/foo.ogg"
curl "https://api.telegram.org/bot$TOKEN/sendVoice?chat_id=$CHAT&voice=$URL"

但我不断收到:

{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}

我确定令牌和聊天 ID 都是正确的,因为我可以使用 sendAudio 方法发送音频(发送 mp3 文件)。我使用的 URL 是 public,来自任何 PC 的 wget 都会下载该文件。

HTTP headers 也是正确的 AFAIK(注意 Content-Type header):

$ curl -v http://server2.mbrt.it:8080/static/foo.ogg >/dev/null
< HTTP/1.1 200 OK
< Server: nginx/1.10.3
< Date: Fri, 09 Jun 2017 14:14:11 GMT
< Content-Type: audio/ogg
< Content-Length: 5881
< Last-Modified: Thu, 08 Jun 2017 23:23:21 GMT
< Connection: keep-alive
< ETag: "5939dc69-16f9"
< Accept-Ranges: bytes

我的猜测是我的编码在某些方面是错误的:

$ file foo.ogg
foo.ogg: Ogg data, Opus audio,

但我尝试使用 ffmpegopusencoggenc 对其进行编码。在所有情况下,我在发送时都会收到相同的错误。

我不知道自己做错了什么。

我自己试了一下 VPS,Telegram 似乎只接受端口 80 用于 HTTP,端口 443 用于 HTTPS :(

你可以下载,用curl -F "voice=@foo.ogg"自己上传