【问题标题】:Telegram bot sendVoice() returns always "wrong file identifier"Telegram bot sendVoice() 总是返回“错误的文件标识符”
【发布时间】:2017-06-10 22:29:39
【问题描述】:

我正在尝试从 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 是公开的,任何 PC 上的wget 都会下载该文件。

HTTP 标头也是正确的 AFAIK(注意 Content-Type 标头):

$ 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 对其进行编码。在所有情况下,我在发送时都会收到相同的错误。

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

【问题讨论】:

    标签: telegram-bot


    【解决方案1】:

    我在自己的 VPS 上试过,似乎 Telegram 只接受端口 80 用于 HTTP,端口 443 用于 HTTPS :(

    您可以下载,使用curl -F "voice=@foo.ogg"自行上传。

    【讨论】:

    • 啊,这很奇怪。事实上,它现在发送文件。我仍然没有将其视为声音,而只是一个文件。看来编码不正确
    猜你喜欢
    • 2018-04-10
    • 2018-09-13
    • 2020-02-28
    • 2016-03-16
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多