Skip to content

Instantly share code, notes, and snippets.

@groza-a-a
Created February 1, 2021 18:39
Show Gist options
  • Save groza-a-a/918adf30bdc2fabb32929e92968e3956 to your computer and use it in GitHub Desktop.
Save groza-a-a/918adf30bdc2fabb32929e92968e3956 to your computer and use it in GitHub Desktop.
$bot_object = new Client($token);
// Загружаем простые команды
$bot_object->command('say_hello', function ($message) use ($bot_object){
$bot_object->sendMessage($message->getChat()->getId(), "Hello!");
});
// Отлавливаем более сложные команды
$bot_object->on(
function($hook) use ($bot_object)
{
$message = false;
$commands = new Commands();
$hook = $commands->parse_hook($hook);
if ($commands->is_command_match('do_some_think', $hook)) {
$message = $commands->do_some_think($hook);
}
elseif ($commands->is_command_match('do_some_think_else', $hook)) {
$message = $commands->do_some_think_else($hook);
}
if (!empty($message)) {
$bot_object->sendMessage($hook->action_chat_id, $message, 'HTML');
}
},
function ($foo)
{
return true;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment