-
-
Notifications
You must be signed in to change notification settings - Fork 962
Cancel all active sessions
Payam Khaninejad edited this page Nov 29, 2016
·
6 revisions
If you want to cancel all active session by a timer or cronjob you can do just like this example:
<?php
// Load composer
require __DIR__ . '/vendor/autoload.php';
require_once 'db.php';
require_once 'class.DBPDO.php';
useLongmanTelegramBotRequest;
useLongmanTelegramBotTelegram;
useCarbonCarbon;
$API_KEY = 'xxxx';
$BOT_NAME = 'xxxx';
$telegram = new Telegram($API_KEY, $BOT_NAME);
$message = "Your session expired please touch /start to start again";
$update = [':status' => "active"];
$pdo = new DBPDO();
$res = $pdo->fetchAll("SELECT * FROM
conversationWHERE
status= 'active' AND
updated_at < '" . Carbon::parse('-15 minute')->toDateTimeString() . "' ", $update);
foreach($res as $user)
{
$chat_id = $user["chat_id"];
`$sql = "UPDATE `conversation` SET `status` = 'stopped' WHERE `conversation`.`id` =" . $user["id"];`
`$pdo->execute($sql);`
`if ($chat_id !== '' && $message !== '')`
`{`
`$data = ['chat_id' => $chat_id, 'text' => $message, ];`
`$result = Request::sendMessage($data);`
`if ($result->isOk())`
`{`
`echo 'Message sent succesfully to: ' . $chat_id . "\n";`
`}`
`else`
`{`
`echo 'Sorry message not sent to: ' . $chat_id . "\n";`
`}`
`}`
}
?>