Quiero hablar sobre el marco PHP para crear bots
BotMan (
sitio ). Botman se puede usar como biblioteca y como extensión de Laravel (BotMan Studio).
La ventaja de este marco es que el código para el bot puede funcionar para muchas plataformas:
- Amazon Alexa
- Chispa de Cisco
- Mensajero de Facebook
- Chat de Hangouts
- Chat de cadera
- Microsoft Bot Framework
- Nexmo
- Holgura
- Telegrama
- Twilio
- Web
- Wechat
- VK
Ejemplo de código:
<?php $botman->hears('Hello BotMan!', function($bot) { $bot->reply('Hello!'); $bot->ask('Whats your name?', function($answer, $bot) { $bot->say('Welcome '.$answer->getText()); }); }); $botman->listen();
Resultado:

Instalar BotMan Studio
Cree un nuevo proyecto en la carpeta botman:
composer create-project --prefer-dist botman/studio botman
Puede verificar la operación a través de la línea de comando:
$ php artisan botman:tinker You: test BotMan: hello!
O consulte a través del navegador. Ejecute el servidor de prueba:
php artisan serve Laravel development server started: <http://127.0.0.1:8000>
Abrir en el navegador
127.0.0.1 : 8000 / botman / tinker
Y escriba hola o inicie una conversación para verificar.
¿Cómo crear un bot para telegram?
En primer lugar, debe registrar el bot con @BotFather.


Todo el bot está registrado y tenemos un token.
En primer lugar, debe instalar el controlador de telegrama:
composer require botman/driver-telegram
Opción A si está utilizando BotMan Studio:
php artisan botman:install-driver telegram
En archivo
config/botman/telegram.php
agrega tu token de Telegram
'telegram' => [ 'token' => 'YOUR-TELEGRAM-TOKEN-HERE', ]
Opción B si no está utilizando BotMan Studio:
DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class); // Create BotMan instance BotManFactory::create($config);
Registrarse Webhook en Telegram
Para que Telegram sepa cómo puede comunicarse con su bot BotMan, debe registrar la URL en la que BotMan trabaja en Telegram.
Puede hacerlo enviando una solicitud POST a esta URL:
https://api.telegram.org/bot<YOUR-TELEGRAM-TOKEN-HERE>/setWebhook
Esta solicitud POST requiere solo un parámetro de URL con una URL que apunte a la ruta BotMan. Si está utilizando Botman Studio, esto será:
https://site.domain/botman
Se requiere HTTPS por razones de seguridad.
En lugar de enviar manualmente una solicitud a Telegram, puede usar el comando de consola para registrar su Webhook. Puede pasar el indicador --output para ver la respuesta de json Telegram.
$ php artisan botman:telegram:register
Buena suerte a todos. Haz bots.