标签: telegram-bot

如何在特定时间发送消息 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万
查看次数

使用 POST 请求 golang 上传文件

我是 golang 的新手,我正在尝试编写一个函数,该函数将一个带有 post 请求的文件上传到我正在编写的机器人的电报。

我已经尝试过使用此代码,但我从电报中得到的错误是 Bad Request: there is no photo in the request.

我在网上搜索过如何做到这一点,但我发现的一切都没有帮助我解决这个问题。

func SendPostRequest (url string, filename string) []byte {
    file, err := os.Open(filename)

    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    response, err := http.Post(url, "binary/octet-stream", file)

    if err != nil {
        log.Fatal(err)
    }
    defer response.Body.Close()

    content, err := ioutil.ReadAll(response.Body)

    if err != nil {
        log.Fatal(err)
    }

    return content
}
Run Code Online (Sandbox Code Playgroud)

我正在调用 SendPostRequest 的函数是

func (e Engine) SendPhoto (filename string, chatId int64) APIResponse { …
Run Code Online (Sandbox Code Playgroud)

httprequest go telegram-bot

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

电报内联机器人 - InlineQueryResultCachedPhoto 不显示标题和描述

我正在使用电报机器人 API来实现内联机器人。为了向用户发送查询结果,我answerInlineQuery以这种方式使用方法。这只是向用户显示存在于电报服务器上的照片的示例:

$results = array(
    array(
        "type" => "photo",
        "id" => "1",
        "photo_file_id" => the file id,
        "title" => "test title",
        "description" => "test description",
        "caption" => "test caption",
        "parse_mode" => "HTML"
    ),
);

$postFields["results"] = json_encode($results);
$postFields["cache_time"] = 0;

//send $postFields to telegram bot api server with curl
Run Code Online (Sandbox Code Playgroud)

这是有效的,在用户发送内联查询后,一张图像显示为结果列表。但问题是两个领域title,并description在结果列表不显示,即使这些都是存在的电报API文档在这里

有什么问题,为什么这两个字段没有出现在结果列表中?

telegram telegram-bot php-telegram-bot

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

使用电报机器人 (telegraf)、nodejs 发送降价文本

如何使用 nodejs 上的电报库通过电报机器人发送降价文本?

node.js telegram telegram-bot telegraf

6
推荐指数
3
解决办法
6682
查看次数

curl: (35) 对等方重置 TCP 连接

我想从 CentOS 设置电报机器人 webhook,但收到错误:

curl: (35) TCP connection reset by peer
Run Code Online (Sandbox Code Playgroud)

我的请求:

curl -F "url=https://12.34.56.78:8443" \
-F "certificate=@/home/mts/mtspredbot/mtspredbot.pem" \
https://api.telegram.org/xxxxxxxxxxxxxxxxxxxxxxx/setWebhook
Run Code Online (Sandbox Code Playgroud)

这个问题与我的输出连接有关还是与其他问题有关?

使用 -v 选项:

$ curl -v -F "url=https://12.34.56.78:8443" -F "certificate=@/home/mts/mtspredbot/mtspredbot.pem" https://api.telegram.org/token_here/setWebhook
* About to connect() to api.telegram.org port 443 (#0)
*   Trying 149.154.167.220...
* Connected to api.telegram.org (149.154.167.220) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -5961 (PR_CONNECT_RESET_ERROR)
* TCP connection reset by peer
* Closing connection 0
curl: (35) …
Run Code Online (Sandbox Code Playgroud)

curl telegram-bot

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

如何在 Telegram bot 中创建弹出通知?

我正在用 C# 开发一个电报机器人。使用类TelegramBotClientTelegram.Bot库中。

我想在点击后创建一个弹出通知InlineKeyboardButton

有谁知道怎么做?非常感谢。

我想创建类似于此图像的内容:

在此处输入图片说明

c# telegram-bot

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

哪些 HTML 标签可用于在 Telegram Bot 上发送消息?

我正在用 C# 开发一个电报机器人。使用类TelegramBotClientTelegram.Bot库中。

我想SendTextMessageAsync使用 HTML 选项发送消息。在官方文档(https://core.telegram.org/bots/api#markdown-style)中,我可以看到:

string texto = @"<b>bold</b>, <strong> bold </strong>" +
               @"<i> italic </i>, <em> italic </em>" +
               @"<a href = 'http://www.example.com/'> inline URL </a>" +
               @"<a href = 'tg://user?id=123456789'> inline mention of a user</a>" +
               @"<code> inline fixed-width code </code>" +
               @"<pre> pre - formatted fixed-width code block</pre>";

 Bot.SendTextMessageAsync(chatId: id_chat,
                          text: texto,
                          parseMode: ParseMode.HTML);
Run Code Online (Sandbox Code Playgroud)

它正常工作,但我想使用“新行”和“列表”。我在电报官方通知上看到过它们,就像这张照片一样:

在此处输入图片说明

我试过<br>, </br>, <br/>……等等。

但我已经得到

Telegram.Bot.Exceptions.ApiRequestException:'错误请求:无法解析实体:字节偏移量为 36 的意外结束标记

有谁知道是否可以做到?

另外如果可以的话联系一个电话号码?

html c# markdown telegram-bot

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

如何发送带有标题/文本的电报媒体组

我目前正在使用python-telegram-bot,基本上我想用它实现的是发送这样的电报消息:

带有 3 张照片和标题的电报帖子

因此,该消息包含 2 张以上的照片/视频,下方带有文本消息。

我已经尝试过的:

  1. 使用send_message方法发送消息,并包括照片 URL,但它只显示文本下方的 1 张图片

  2. 使用send_media_group发送媒体组,但此方法没有caption作为send_photo 的参数。

python telegram python-telegram-bot telegram-bot

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

如何获取 Telegram Bot 统计数据?

是否有任何方法可以使用 API 或 Web 界面或 BotFather 获取机器人的统计信息?或者我必须通过处理来自机器人 API 的更新来收集统计信息?

附:目前我通过处理来自机器人 API 的更新将统计信息存储在 Redis 中,但我希望找到更好的方法。

telegram-bot php-telegram-bot

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