0

我正在创建一个电报机器人,需要x 回调到另一个应用程序。

这是我打开 VLC 并流式传输视频的 x-callback。当我在 Siri Shortcuts 或 Safari 中使用它时效果很好。但我需要它来处理 Telegram 聊天对话。

vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4

当我将其作为原始文本发送时,它显然不会将其识别为有效的 url,并且什么也不做。我尝试将其格式化为MarkdownMarkdownV2HTML样式,但均无效。我也试过InlineKeyboardButton给它texturl但它抛出一个BadRequest错误

telegram.error.BadRequest: Inline keyboard button url is invalid

从 Telegram 到另一个应用程序的 x-callback 是否有任何解决方法?

我的问题与实现无关,但这是我使用python-telegram-bot 的代码

from telegram import Update, ParseMode, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CommandHandler, CallbackContext, Updater


my_x_callback = 'vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4'

def test(update: Update, context: CallbackContext):
    update.message.reply_text(my_x_callback)
    update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN)
    update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN_V2)
    update.message.reply_text(f'<a href="{my_x_callback}">Play it on VLC</a>', parse_mode=ParseMode.HTML)
    button = InlineKeyboardButton('Play it on VLC', url=my_x_callback)
    update.message.reply_text(
        'Testing InlineKeyboard',
        reply_markup=InlineKeyboardMarkup([[button]])
    )

if __name__ == '__main__':
    updater = Updater('TOKEN')
    updater.dispatcher.add_handler(CommandHandler('test', test))
    updater.start_polling()
    updater.idle()

4

1 回答 1

0

I had a similar use case once where I wanted to use mailto: links. My workaround is to create a website URL that points to the mailto: link. I.e. flow is:

  1. Generate mailto link depending on users request
  2. Generate https:// url that points to the link - in my case that's done via a self-hosted YOURLS instance
  3. used that generated URL either for an inline buttton or as text link.
于 2021-09-26T20:32:45.033 回答