Commit 4d9e1f09 authored by MBoretto's avatar MBoretto

Merged sabas in develop

parents afe39d7e 695306ee
......@@ -90,14 +90,14 @@ And run composer update
composer require longman/telegram-bot
```
###### bot token
###### Bot token
You will notice that the Telegram Bot wants a value for `API_KEY`. This token may be obtained via a telegram client for your bot. See [this](https://core.telegram.org/bots#botfather) link if you are unsure of how to so this.
## Usage
You must set [WebHook](https://core.telegram.org/bots/api#setwebhook)
You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook)
Create set.php and put:
Create set.php and put into it:
```php
<?php
$loader = require __DIR__.'/vendor/autoload.php';
......@@ -165,9 +165,9 @@ It can execute command triggering a chat event. Here's the list:
- New chat title (**NewchattitleCommand.php**)
- Left chat participant (**LeftchatparticipantCommand.php**)
**GenericCommand.php** let you handle commands that non exists or use commands as variable:
Favourite colour? **/black, /red**
Favourite number? **/1, /134**
**GenericCommand.php** lets you handle commands that don't exist or to use commands as a variable:
Favourite colour? **/black, /red**
Favourite number? **/1, /134**
Maybe you would like to develop your own commands. A good practice is to store them outside vendor/. This can be done adding the method:
......
......@@ -17,7 +17,7 @@ use Longman\TelegramBot\Entities\Update;
class GenericCommand extends Command
{
protected $name = 'Generic';
protected $description = 'Handle generic commands or is executed by defaul when a command is not found';
protected $description = 'Handle genric commands or is executed by default when a command is not found';
protected $usage = '/';
protected $version = '1.0.0';
protected $enabled = true;
......@@ -30,7 +30,10 @@ class GenericCommand extends Command
//you can use $command as param
$command = $message->getCommand();
$data = [];
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data['chat_id'] = $chat_id;
$data['text'] = 'Command: '.$command.' not found.. :(';
$result = Request::sendMessage($data);
......
<?php
/*
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
class SlapCommand extends Command
{
protected $name = 'slap';
protected $description = 'Slap someone with their username';
protected $usage = '/slap <@user>';
protected $version = '1.0.0';
protected $enabled = true;
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$sender='@'.$message->getFrom()->getUsername();
//username validation
$test=preg_match('/@[\w_]{5,}/', $text);
if ($test===0) {
return false;
}
$data = array();
$data['chat_id'] = $chat_id;
$data['text'] = $sender.' slaps '.$text.' around a bit with a large trout';
$result = Request::sendMessage($data);
return $result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment