gjae/laravel-telegram-log 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gjae/laravel-telegram-log

Composer 安装命令:

composer require gjae/laravel-telegram-log

包简介

README 文档

README

Installing dependency via composer

composer require gjae/laravel-telegram-log

Once you have installed this package, execute the following command at laravel command prompt:

php artisan vendor:publish --provider="Gjae\TelegramLogChannel\Providers\TelegramChannelProvider"

It will create a file named config/telegram_channel.php. It has the basic config. Now you will need to add a "chat ID" and a "bot api token" in this file.

Quickstarter with telegram bots

Creation of new bots is managed by the BotFather.

Search @BotFather on telegram or click here: botfhater.

Now, create a new bot by typing the command /newbot into the BotFather chat box or choose it by clicking on the square button at the rigth corner of the chat box. Then, select "/newbot". The name of your new bot must have the suffix "Bot", for example:"laravel_log_bot", "LaravelBot". The BotFather will ask you for a name and a username for your new bot (both of them must have the suffix "Bot").

finally, the @BotFather will send you a message like this:

Done! Congratulations on your new bot. You will find it at t.me/[YourUsernameBot]. 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: [TOKEN] Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: https://core.telegram.org/bots/api

GREAT, you have already created your first telegram bot.

Next, copy the token (the one that has the format XXXX:YYYYYYYY) and save it in a safe place.

Usage

Open your ".env file" and look for the following lines and paste the Token and Telegram Id (the ones you had copied before) as values for the following variables:

  1. TELEGRAM_BOT_ACCESS_TOKEN= paste here your SECRET BOT API TOKEN .,
  2. TELEGRAM_CHAT_ID= paste here your chat ID

NOTE 1: Sometimes the ID value may have a "-" mark at the beginning; you should copy this symbol too.

NOTE 2: IF THE ID VALUE HAS ANY SYMBOL AT THE BEGINING, PUT THE ID VALUE INSIDE QUOTATION MARKS. Example: "-121412312"

next open the config/logging.php file, look for the "channels" array and overwrite it like this:

[
    ...
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['telegram', 'daily'],
        ],

        'telegram'  =>[
            'driver'  => 'monolog',
            'handler' => \Gjae\TelegramLogChannel\TelegramChannel::class,
            'level'   => 'error'
        ],

        ...
    ]
]

How to get the chat_id value

You can make a request to the url: [https://api.telegram.org/bot[YourBotAccessToken]/getUpdates] (https://api.telegram.org/bot[YourBotAccessToken]/getUpdates) (change [YourBotAccessToken] by the "bot token" you have just gotten). Now you'll get a json like this:

{
    "ok": true,
    "result": [
        {
            "update_id": 193532624,
            "message": {
                "message_id": 2,
                "from": {
                    "id": 259222478,
                    "is_bot": false,
                    "first_name": ....,
                    "last_name": ...,
                    "username": ...,
                    "language_code": ...
                },
                "chat": {
                    "id": 259222478,
                    "first_name": ....,
                    "last_name": ...,
                    "username": ...,
                    "type": "private"
                },
                "date": 1589138780,
                "text": "@channelusername",
                "entities": [
                    {
                        "offset": 0,
                        "length": 16,
                        "type": "mention"
                    }
                ]
            }
        },
    ]
}

YOU'RE DONE!

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固