leocata / m1-bot
PHP API M1
1.0.1
2017-10-25 05:49 UTC
Requires
- leocata/m1-api: ^0
- ratchet/pawl: ^0.3
- ulrichsg/getopt-php: ^3.0
Requires (Dev)
- phpunit/php-code-coverage: ^5.2
- phpunit/phpunit: ^6.4
- squizlabs/php_codesniffer: ^3.0
This package is not auto-updated.
Last update: 2025-03-30 06:29:56 UTC
README
Install Gearman server
apt-get install gearman software-properties-common
add-apt-repository ppa:gearman-developers/ppa
add-apt-repository ppa:ondrej/pkg-gearman
apt-get update
apt-get install php-gearman
Install Application
composer require leocata/m1-bot
Usage
Create bot
ExampleBot.php
<?php
use leocata\m1Bot\Bot\BaseBot;
class ExampleBot extends BaseBot
{
public $pass = 'password';
public $username = 'username';
public function contactRequested(\GearmanJob $job)
{
$message = json_decode($job->workload());
$this->getApiWrapper()->contactAccept($message->userid, '', 1);
$job->sendComplete(true);
}
public function message(\GearmanJob $job)
{
$this->getApiWrapper()->messageDelivered($message->sessionid, $message->id);
$this->getApiWrapper()->messageTyped($message->sessionid, $message->orig);
$job->sendComplete(true);
}
}
Start Example Bot
Start WebSocket client
vendor/bin/mbot-cli websocket --bot ExampleBot
Start Gearman workers
vendor/bin/mbot-cli gearman --bot ExampleBot
Use supervisor
Add file /etc/supervisor/conf.d/websocket_client_exampleBot.conf
[program:websocket_client_exampleBot]
command = vendor/bin/mbot-cli websocket --bot ExampleBot
process_name = websocket_client
numprocs = 1
autostart = true
autorestart = true
user = mbot
stdout_logfile = /var/logs/exampleBot-websocket-info.log
stdout_logfile_maxbytes = 1MB
stderr_logfile = /var/logs/exampleBot-websocket-error.log
Add file /etc/supervisor/conf.d/gearman_worker_exampleBot.conf
[program:gearman_worker_exampleBot]
command = vendor/bin/mbot-cli gearman --bot ExampleBot
process_name = websocket_client
numprocs = 1
autostart = true
autorestart = true
user = mbot
stdout_logfile = /var/logs/exampleBot-gearman-info.log
stdout_logfile_maxbytes = 1MB
stderr_logfile = /var/logs/exampleBot-gearman-error.log