gpt4 book ai didi

java - 通过 Telegram Bot 将图像发布到 Telegram channel

转载 作者:行者123 更新时间:2023-11-30 10:21:06 27 4
gpt4 key购买 nike

我在使用机器人将照片发送到 channel 时遇到问题。我试图找到一个如何做到这一点的例子。我有这段代码:

SendPhoto sendPhoto = new SendPhoto();
sendPhoto.setCaption("My Caption!");
sendPhoto.setNewPhoto(new File("/Users/user/Desktop/photo.png"));
sendPhoto.setChatId("@test_channel");

另外,我有 apiToken。但我不明白如何将这张照片发送到 channel 。有人可以帮助我吗?

最佳答案

如果您想首先将照片发送到 channel ,您应该将机器人作为管理员添加到 channel ,然后您应该找到 channel 的 channel ID,因为当您想要发送图像时需要知道这些你需要做的是:

try 
{
sendPhoto(sendPhoto); // Call method to send the photo with caption
}
catch (TelegramApiException e)
{
e.printStackTrace();
}

顺便说一下,您还可以将图像发送到您的机器人并提取图像的文件 ID,然后尝试使用文件 ID 发送它。这样您的机器人就不会使用您的本地服务器。

关于java - 通过 Telegram Bot 将图像发布到 Telegram channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47979353/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com