c# - 发送照片电报 API

标签 c# telegram-bot

我想使用 Telegram.Bot 发送照片图书馆,但它不工作!

这是我的代码:

private void btnSendImage_Click(object sender, RoutedEventArgs e)
    {
        var Bot = new Telegram.Bot.Api(token);

        Task<Telegram.Bot.Types.Update[]> res = Bot.GetUpdates();

        List<string> users = GetIds();
        foreach (var update in res.Result)
        {
            if (!users.Contains("" + update.Message.Chat.Id))
            {
                AddId("" + update.Message.Chat.Id);

            }
        }
        users = GetIds();
        foreach (var item in users)
        {
            if (item.Length > 0)
            {

                var rep = Bot.SendPhoto(Convert.ToInt32(item), txtImagePath.Text, txtMessage.Text);
            }
        }

    }

and txtImagePath.text= "D:\Projects\Telegram Bot\Telegram Bot\bin\Debug\4.jpg";

我用 Bot.SendMessage 测试了它,它工作正常,但我不能发送照片!

最佳答案

我使用了这段代码,它成功了!

var FileUrl = @"C:\\Users\\User\\Documents\\20160201_204055.jpg";
using (var stream = System.IO.File.Open(FileUrl, FileMode.Open))
        {
            FileToSend fts = new FileToSend();
            fts.Content = stream;
            fts.Filename = FileUrl.Split('\\').Last();
            var test = await bot.SendPhoto("@channel Name or chat_id", fts, "My Text");
        }

关于c# - 发送照片电报 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32284958/

相关文章:

c# - C# 中的谷歌分析

c# - Case/switch 语句 c#?

python - Telegram Bot API - 上传带有文件名的文档

telegram - 如何让 Telegram Bot 将消息发布到我的 channel 而不是它自己的 channel

telegram-bot - 如何知道 Telegram 机器人已被用户停止/阻止?

c# - 如何在 Winform 中使用多线程?

c# - WPF:两个控件绑定(bind)到一个源,如何过滤绑定(bind)?

c# - 如何调试与低级 API(如 I/O 完成端口)交互的代码?

python - 如何在 Telegram Bot 中获取用户名?

mysql - 使用 MySql 与 json 文件作为 python telegram bot 的用户数据库