Commit c7837b02 authored by MBoretto's avatar MBoretto

new command structure in examples

parent 9828c736
...@@ -28,7 +28,8 @@ The Bot can: ...@@ -28,7 +28,8 @@ The Bot can:
- handle commands in chat with other bots. - handle commands in chat with other bots.
- manage Channel from the bot admin interface. - manage Channel from the bot admin interface.
- full support for **inline bots**. (**new!**) - full support for **inline bots**. (**new!**)
- Messages, InlineQuery and ChosenInlineQuery are stored in the Database. (**new!**) - Messages, InlineQuery and ChosenInlineQuery are stored in the Database.
- Conversation feature (**new!**)
----- -----
This code is available on This code is available on
...@@ -397,7 +398,7 @@ $telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_he ...@@ -397,7 +398,7 @@ $telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_he
Enabling this feature, the admin bot can perform some super user commands like: Enabling this feature, the admin bot can perform some super user commands like:
- Send message to all chats */sendtoall* - Send message to all chats */sendtoall*
- List all the chats started with the bot */chats* - List all the chats started with the bot */chats*
- Send a message to your channels */sendtochannel* (NEW! see below how to configure it) - Post any content to your channels */sendtochannel* (NEW! see below how to configure it)
You can specify one or more admins with this option: You can specify one or more admins with this option:
```php ```php
......
<?php <?php
/**
/*
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* Written by <marco.bore@gmail.com> */
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request; namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup; use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ReplyKeyboardHide; use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ForceReply; use Longman\TelegramBot\Entities\ForceReply;
class ForceReplyCommand extends Command /**
* User "/forcereply" command
*/
class ForceReplyCommand extends UserCommand
{ {
/**#@+
* {@inheritdoc}
*/
protected $name = 'forcereply'; protected $name = 'forcereply';
protected $description = 'Force reply with reply markup'; protected $description = 'Force reply with reply markup';
protected $usage = '/forcereply'; protected $usage = '/forcereply';
protected $version = '0.0.5'; protected $version = '0.0.5';
protected $enabled = true; /**#@-*/
/**
* {@inheritdoc}
*/
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array(); $data = [];
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
$data['text'] = 'Write something:'; $data['text'] = 'Write something:';
#$data['reply_to_message_id'] = $message_id; $data['reply_markup'] = new ForceReply(['selective' => false]);
$force_reply = new ForceReply(['selective' => false]);
#echo $json;
$data['reply_markup'] = $force_reply;
$result = Request::sendMessage($data); return Request::sendMessage($data);
return $result;
} }
} }
<?php <?php
/**
/*
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* Written by Marco Boretto <marco.bore@gmail.com> */
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request; namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup; use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ForceReply;
class HidekeyboardCommand extends Command /**
* User "/hidekeyboard" command
*/
class HidekeyboardCommand extends UserCommand
{ {
/**#@+
* {@inheritdoc}
*/
protected $name = 'hidekeyboard'; protected $name = 'hidekeyboard';
protected $description = 'Hide the custom keyboard'; protected $description = 'Hide the custom keyboard';
protected $usage = '/hidekeyboard'; protected $usage = '/hidekeyboard';
protected $version = '0.0.5'; protected $version = '0.0.5';
protected $enabled = true; /**#@-*/
/**
* {@inheritdoc}
*/
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array(); $data = [];
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
$data['text'] = 'Keyboard Hided'; $data['text'] = 'Keyboard Hided';
#$data['reply_to_message_id'] = $message_id; $data['reply_markup'] = new ReplyKeyboardHide([ 'selective' => false]);
$reply_keyboard_hide = new ReplyKeyboardHide([ 'selective' => false]);
$data['reply_markup'] = $reply_keyboard_hide;
$result = Request::sendMessage($data); return Request::sendMessage($data);
return $result;
} }
} }
<?php <?php
/**
/*
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Longman\TelegramBot\Commands;
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\Update;
class ImageCommand extends Command /**
* User "/image" command
*/
class ImageCommand extends UserCommand
{ {
/**#@+
* {@inheritdoc}
*/
protected $name = 'image'; protected $name = 'image';
protected $description = 'Send Image'; protected $description = 'Send Image';
protected $usage = '/image'; protected $usage = '/image';
protected $version = '1.0.0'; protected $version = '1.0.0';
protected $enabled = true; /**#@-*/
protected $public = true;
/**
* {@inheritdoc}
*/
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true); $text = $message->getText(true);
$data = array(); $data = [];
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
$data['caption'] = $text; $data['caption'] = $text;
return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
//$result = Request::sendDocument($data,'structure.sql');
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
$result = Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
return $result;
} }
} }
<?php <?php
/**
/*
* This file is part of the TelegramBot package. * This file is part of the TelegramBot package.
* *
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com> * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* written by Marco Boretto <marco.bore@gmail.com> */
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request; namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup; use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ForceReply;
class KeyboardCommand extends Command /**
* User "/keyboard" command
*/
class KeyboardCommand extends UserCommand
{ {
/**#@+
* {@inheritdoc}
*/
protected $name = 'keyboard'; protected $name = 'keyboard';
protected $description = 'Show a custom keybord with reply markup'; protected $description = 'Show a custom keybord with reply markup';
protected $usage = '/keyboard'; protected $usage = '/keyboard';
protected $version = '0.0.5'; protected $version = '0.0.5';
protected $enabled = true; /**#@-*/
/**
* {@inheritdoc}
*/
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true); $text = $message->getText(true);
$data = array(); $data = [];
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
$data['text'] = 'Press a Button:'; $data['text'] = 'Press a Button:';
#$data['reply_to_message_id'] = $message_id;
//Keyboard examples
#Keyboard examples $keyboards = [];
$keyboards = array();
//0 //0
$keyboard[] = ['7','8','9']; $keyboard[] = ['7','8','9'];
...@@ -64,7 +62,6 @@ class KeyboardCommand extends Command ...@@ -64,7 +62,6 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard); unset($keyboard);
//2 //2
$keyboard[] = ['A']; $keyboard[] = ['A'];
$keyboard[] = ['B']; $keyboard[] = ['B'];
...@@ -73,8 +70,6 @@ class KeyboardCommand extends Command ...@@ -73,8 +70,6 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard); unset($keyboard);
//3 //3
$keyboard[] = ['A']; $keyboard[] = ['A'];
$keyboard[] = ['B']; $keyboard[] = ['B'];
...@@ -83,8 +78,7 @@ class KeyboardCommand extends Command ...@@ -83,8 +78,7 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard); unset($keyboard);
$data['reply_markup'] = new ReplyKeyboardMarkup(
$reply_keyboard_markup = new ReplyKeyboardMarkup(
[ [
'keyboard' => $keyboards[1] , 'keyboard' => $keyboards[1] ,
'resize_keyboard' => true, 'resize_keyboard' => true,
...@@ -92,10 +86,7 @@ class KeyboardCommand extends Command ...@@ -92,10 +86,7 @@ class KeyboardCommand extends Command
'selective' => false 'selective' => false
] ]
); );
#echo $json;
$data['reply_markup'] = $reply_keyboard_markup;
$result = Request::sendMessage($data); return 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