php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.88k stars 955 forks source link

DB LOG - Custom Script #1409

Closed OurWin closed 1 year ago

OurWin commented 1 year ago

Hello everyone,

I have a script that automatically sends a message to my users when an action is performed on my server.

The message is sent successfully, but the message is not recorded in the database. Any ideas? :)

Here is the script:

<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$config = require __DIR__ . '/../../config.php';
require_once __DIR__ . '/../require/DB.php';
require_once __DIR__ . '/../require/utils.php';

use Longman\TelegramBot\Request;

$telegram = new Longman\TelegramBot\Telegram($config['api_key'], $config['bot_username']);
$telegram->enableMySql($config['mysql']);

$user_id = $_GET["id"];

if(is_active($user_id) == "active"){

    $result = Request::sendMessage([
        'chat_id' => $user_id,
        'text'    => "MESSAGE",
    ]);

}

?>
iyamk commented 1 year ago

For such purposes you need this https://github.com/php-telegram-bot/core/blob/develop/doc/01-utils.md#initialisation And here select the database that you have https://github.com/Seldaek/monolog/blob/main/doc/02-handlers-formatters-processors.md#log-to-databases And if it doesn’t work, then make a function that will send a message and then log it to the database

noplanman commented 1 year ago

As @iyamk has suggested, the bot does not log sent messages automatically, you'll need to do that yourself.