标签: telegram-bot

Python Telegram Bot - 发送图像

我想根据要求发送图像(通过 URL 或路径)。我在这里使用源代码。 该代码已经有一个发送图像的示例(通过 URL 或路径),但我不明白,因为我是 Python 的新手。

这是示例代码片段:

elif text == '/image':        #request
    img = Image.new('RGB', (512, 512))
    base = random.randint(0, 16777216)
    pixels = [base+i*j for i in range(512) for j in range(512)]  # generate sample image
    img.putdata(pixels)
    output = StringIO.StringIO()
    img.save(output, 'JPEG')
    reply(img=output.getvalue())
Run Code Online (Sandbox Code Playgroud)

一些 API 信息可以在这里找到。

谢谢你的耐心。

python api image telegram-bot

6
推荐指数
1
解决办法
1万
查看次数

如何在 Telegram BotFather 中设置创建的游戏的 Url?

我在 BotFather Telegram 中创建了一个新游戏。但是没有关于游戏链接的任何问题。此外,在“sendGame”函数中没有任何参数来设置游戏网址。如何在 BotFather 创建的游戏后面设置我的 gameUrl?

我应该说,我正在使用 Microsoft Bot Framework 来开发我的机器人。

webhooks telegram-bot botframework telegram-webhook

6
推荐指数
1
解决办法
1181
查看次数

如何在 Telegram 上获取联系人

我将 node.js 模块用于 Telegram bot。我正在尝试使用电报 API 获取用户的电报联系人。Telegram API 有两种类型:Bot API 和 Telegram API

我认为 Bot API 无法获取用户的联系人。在 Telegram API 中有方法contact.getContacts. 但我不知道如何使用它。

如何获取 Telegram 上的联系人?

architecture node.js telegram telegram-bot

6
推荐指数
2
解决办法
5388
查看次数

从 Telegram Bot API 获取回复消息

我正在开发一个机器人,我希望用户在回复之前的消息时调用它。因此,您将使用 bot 命令回复消息。

例如
用户 1:Hello World
用户 2:(回复 Hello World)/command 测试消息

现在我只能获取命令中直接发送的文本(“测试消息”),而不能获取第一条消息(“Hello World”)。根据他们的文档,我应该能够从reply_to_message. 但是,我在 webhook 的日志中看到的只是这个。

event: {
  body: {
    update_id: 5632431,
    message: {
      message_id: 43,
      from: {
        id: < my_user_id > ,
        first_name: 'User 2',
        username: 'user_2_username',
        language_code: 'en'
      },
      chat: {
        id: < chat_id > ,
        title: < chat_name > ,
        type: 'group',
        all_members_are_administrators: true
      },
      date: 1498342725,
      text: '/command test message',
      entities: [{
        type: 'bot_command',
        offset: 0,
        length: 5
      }]
    }
  } …
Run Code Online (Sandbox Code Playgroud)

telegram telegram-bot

6
推荐指数
1
解决办法
1万
查看次数

如何从 BOT Telegram 发送的消息中获取 Message_id?

我对bot电报进行编程。

message_id当我向 Group 发送消息时,我想要 Get By Bot。

我的代码是PHP.

$token = "MY_BOT's_TOKEN";

$data = [
    'text' => 'my message here',
    'chat_id' => 'the_chat_id_here'
];

file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) );
Run Code Online (Sandbox Code Playgroud)

怎么办?

最良好的问候。

php telegram-bot

6
推荐指数
1
解决办法
5916
查看次数

PythonBot - 将参数传递给命令处理程序

我正在玩 Python Telegram Bot,我想将先前计算获得的参数传递给我的处理程序,例如:

def my_handler(bot, update, param):
    print(param)

def main():
    res = some_function()
    updater.dispatcher.add_handler(CommandHandler('cmd', my_handler))
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给处理程序?

python python-telegram-bot telegram-bot

6
推荐指数
2
解决办法
8821
查看次数

在 Heroku 上使用 Go、GoLang 的 Telegram Bot API Webhooks

go-telegram-bot-api用于构建 Telegram Bot 并将其部署在Heroku 上

我需要像以前在 Python 中所做的那样设置 Webhooks,就像在这个 Python 案例中一样

无法理解如何在go-telegram-bot-api不提供证书文件的情况下设置 Webhooks 。

主要示例包含以下几行:

如果您需要使用网络钩子(如果您希望在 Google App Engine 上运行),您可以使用稍微不同的方法。

package main

import (
    "gopkg.in/telegram-bot-api.v4"
    "log"
    "net/http"
)

func main() {
    bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
    if err != nil {
        log.Fatal(err)
    }

    bot.Debug = true

    log.Printf("Authorized on account %s", bot.Self.UserName)

    _, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
    if err != nil {
        log.Fatal(err)
    }

    updates := bot.ListenForWebhook("/" + bot.Token)
    go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) …
Run Code Online (Sandbox Code Playgroud)

heroku go webhooks telegram-bot telegram-webhook

6
推荐指数
1
解决办法
3448
查看次数

如何在特定时间发送消息 TelegramBot

嗨,我想在特定时间从机器人发送消息(没有我的消息),例如每个星期六早上 8:00。这是我的代码:

import telebot
import config
from datetime import time, date, datetime

bot = telebot.TeleBot(config.bot_token)
chat_id=config.my_id    

@bot.message_handler(commands=['start', 'help'])
def print_hi(message):
    bot.send_message(message.chat.id, 'Hi!')


@bot.message_handler(func=lambda message: False) #cause there is no message
def saturday_message():
    now = datetime.now()
    if (now.date().weekday() == 5) and (now.time() == time(8,0)):
        bot.send_message(chat_id, 'Wake up!')

bot.polling(none_stop=True)
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用。试过

urlopen("https://api.telegram.org/bot" +bot_id+ "/sendMessage?chat_id=" +chat_id+ "&text="+msg)
Run Code Online (Sandbox Code Playgroud)

但又没有结果。不知道该怎么办,请帮忙指点迷津。

python python-3.x telegram telegram-bot

6
推荐指数
2
解决办法
8959
查看次数

无需用户输入即可向电报组发送消息

我正在尝试构建一个机器人,它会在使用 python 的最新新闻中有更新时自动发送消息。以下是我所做的。

companies = {
    "name_1": {
        "rss": "name_1 rss link",
        "link": "name_1 link"
    }
}

import feedparser as fp
import time, telebot
token = <TOKEN>
bot = telebot.TeleBot(token)
LIMIT = 1
while True:
    def get_news():
        count = 1
        news = []
        for company, value in companies.items():
            count = 1
            if 'rss' in value:
                d = fp.parse(value['rss'])
                for entry in d.entries:
                    if hasattr(entry, 'published'):
                        if count > LIMIT:
                            break
                        news.append(entry.link)
                        count = count + 1

        return (news)
    val = …
Run Code Online (Sandbox Code Playgroud)

python-3.x telegram python-telegram-bot telegram-bot

6
推荐指数
2
解决办法
2万
查看次数

如何管理私人频道的邀请链接?

我做了什么:

Telegram使用TelegrafJS框架开发了一个机器人。这个机器人允许用户订阅付费频道,这个频道是私有的。

所以支付完成后,机器人会发送邀请链接,让用户加入频道。

问题

现在假设付费用户将邀请链接发送给另一个用户(谁没有付费),非付费用户将获得对付费频道的访问,就像付费一样。

在想解决办法之前,有必要了解一下Telegram的邀请链接的限制:

  • 如果没有邀请链接,则无法将用户添加到频道;
  • 无法创建一次性邀请链接;
  • 无法创建个人邀请链接(只有一个用户可以使用);
  • 邀请链接缓存在 Telegram 服务器上,如果您将它们重置得太快就会变得不稳定(尝试使用 Telegram 应用程序在 10 秒内重置链接 2-3 次——您会明白我的意思)。

我认为的解决方案

我想在一个内嵌按钮后面显示邀请链接,所以用户会看到点击这里按钮 3 秒钟,然后这将被撤销并创建另一个链接。这并没有消除无需付费订阅即可访问付费频道的问题,但它使不公平用户的生活变得更加困难。

可能的其他问题:当用户点击链接时:

抱歉,此频道似乎不存在。

这意味着该频道的邀请链接目前不稳定。它通常发生在连续多次单击“加入”之后,或者如果多个用户同时尝试加入。

尝试次数过多,请稍后再试

这意味着用户最近点击了太多无效的邀请链接。最有可能的是,他在此之前收到了很多消息“对不起,此频道似乎不存在”,或者连续加入了太多频道/群组。

结论

有没有更安全的方法来处理这个问题?

node.js telegram telegram-bot node-telegram-bot-api

6
推荐指数
1
解决办法
7984
查看次数