smart-gamma / symfony-errors-telegram-bot
该Telegram机器人允许将关于Symfony关键错误的通知发送到配置的项目聊天室
v1.0.9
2020-04-06 13:14 UTC
Requires
- php: >=5.6
- simonbackx/slack-php-webhook: ^1.0
- symfony/console: ^2.3|^3.0|^4.0
- symfony/swiftmailer-bundle: ^2.3|^3.0|^4.0
- symfony/twig-bundle: ^2.3|^3.0|^4.0
- telegram-bot/api: ^2.3
- dev-master
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/composer/twig/twig-2.15.3
- dev-dependabot/composer/symfony/http-kernel-3.4.49
- dev-dependabot/composer/symfony/mime-4.4.7
- dev-dependabot/composer/symfony/http-foundation-4.4.7
- dev-fix-process-request-error
- dev-dependabot/composer/symfony/var-exporter-4.4.4
- dev-dependabot/composer/symfony/cache-4.3.9
- dev-slack
This package is not auto-updated.
Last update: 2024-09-17 10:33:35 UTC
README
该Telegram机器人允许将关于Symfony关键错误的提醒发送到配置的项目聊天室
1. 安装
composer require smart-gamma/symfony-errors-telegram-bot
2. 配置
2.1. 激活包
Symfony版本 < 4.0
添加到AppKernel.php
new Gamma\ErrorsBundle\GammaErrorsBundle(),
使用dotenv的Symfony
添加到app/config/service.yaml
parameters:
gamma.base_host: '%env(BASE_URI)%'
在.env文件中定义"BASE_URI",或用定义项目基础URI的env变量替换它。
不使用dotenv的Symfony
添加到parameter.yml
gamma.base_host: 'put your base uri here'
2.2. 添加配置
将gamma_errors_bot.yaml文件放置在app/config目录下的vendor/packages文件夹中
gamma_errors:
enabled: true
telegram_channel:
auth_key: '%env(GAMMA_ERRORS_TELEGRAM_AUTH_KEY)%'
chat_id: '%env(GAMMA_ERRORS_TELEGRAM_CHAT_ID)%'
3. 创建机器人
与@BotFather开始对话。
You: /newbot
>>>>>>>>>>
@BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.
<<<<<<<<<<
You: Sample Error Bot
>>>>>>>>>>
@BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example:
TetrisBot or tetris_bot.
<<<<<<<<<<
Me: test_error_bot
>>>>>>>>>>
@BotFather: Done! Congratulations on your new bot. You will find it at telegram.me/cronus_bot. You can now add a
description, about section and profile picture for your bot, see /help for a list of commands. By the way, when
you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure
the bot is fully operational before you do this.
Use this token to access the HTTP API:
111111:xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
4. 获取聊天标识符
创建的机器人添加到项目群组后,应检索其chat_id
向URL: https://api.telegram.org/bot_token_/getUpdates 发送POST请求
示例
请求
curl -X POST https://api.telegram.org/bot111111:xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates
响应
{
"ok": true,
"result": [
{
"update_id": 222222,
"message": {
"message_id": 3333,
"from": {
"id": 444444,
"first_name": "Test",
"last_name": "Test",
"username": "test"
},
"chat": {
"id": -111111
"first_name": "Test",
"last_name": "Test",
"username": "test",
"type": "private"
},
"date": 1480701504,
"text": "test"
}
}
]
}
chat_id是数字“-111111”。
- Slack支持
为了有额外的通知渠道,您可以启用Slack和webhook集成
-
将" Incoming WebHooks"应用到Slack,并从设置中复制webhook URL
-
配置
gamma_errors:
enabled: true
telegram_channel:
....
slack_channel:
webhook: '%env(GAMMA_ERRORS_SLACK_WEBHOOK)%'
channel: '%env(GAMMA_ERRORS_SLACK_CHANNEL)%'