【问题标题】:Why i get Wrong file identifier/HTTP URL specified error in telegram bot?为什么我在电报机器人中收到错误的文件标识符/HTTP URL 指定错误?
【发布时间】:2017-03-17 23:06:03
【问题描述】:

我是电报机器人的新手,并尝试使用此代码向用户发送照片:

await Bot.SendPhotoAsync(update.Message.Chat.Id, "http://182.126.201.42/" + "iisstart" + ".png");


但是当我尝试运行该代码时,出现此错误:

Bad Request: Wrong file identifier/HTTP URL specified


我该如何解决这个问题?谢谢。

【问题讨论】:

标签: c# telegram-bot


【解决方案1】:

问题可能源于以下问题:

  • 电报不允许该图像文件扩展名。
  • 文件大小大于电报允许的大小。

你可以从前一个开始。

【讨论】:

    【解决方案2】:

    编码至example可以发照片:

    await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadPhoto);
    
                const string file = @"<FilePath>";
    
                var fileName = file.Split('\\').Last();
    
                using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var fts = new FileToSend(fileName, fileStream);
    
                    await Bot.SendPhotoAsync(message.Chat.Id, fts, "Nice Picture");
                }
    

    文档:https://mrroundrobin.github.io/telegram.bot/html/M_Telegram_Bot_TelegramBotClient_SendPhotoAsync_3.htm

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 2021-03-21
      • 2021-03-18
      • 1970-01-01
      • 2015-12-12
      相关资源
      最近更新 更多