Commit c7837b02 authored by MBoretto's avatar MBoretto

new command structure in examples

parent 9828c736
......@@ -28,7 +28,8 @@ The Bot can:
- handle commands in chat with other bots.
- manage Channel from the bot admin interface.
- 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
......@@ -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:
- Send message to all chats */sendtoall*
- 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:
```php
......
<?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.
* Written by <marco.bore@gmail.com>
*/
namespace Longman\TelegramBot\Commands;
*/
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ForceReply;
class ForceReplyCommand extends Command
/**
* User "/forcereply" command
*/
class ForceReplyCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'forcereply';
protected $description = 'Force reply with reply markup';
protected $usage = '/forcereply';
protected $version = '0.0.5';
protected $enabled = true;
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Write something:';
#$data['reply_to_message_id'] = $message_id;
$force_reply = new ForceReply(['selective' => false]);
#echo $json;
$data['reply_markup'] = $force_reply;
$data['reply_markup'] = new ForceReply(['selective' => false]);
$result = Request::sendMessage($data);
return $result;
return 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.
* Written by Marco Boretto <marco.bore@gmail.com>
*/
namespace Longman\TelegramBot\Commands;
*/
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
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 $description = 'Hide the custom keyboard';
protected $usage = '/hidekeyboard';
protected $version = '0.0.5';
protected $enabled = true;
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Keyboard Hided';
#$data['reply_to_message_id'] = $message_id;
$reply_keyboard_hide = new ReplyKeyboardHide([ 'selective' => false]);
$data['reply_markup'] = $reply_keyboard_hide;
$data['reply_markup'] = new ReplyKeyboardHide([ 'selective' => false]);
$result = Request::sendMessage($data);
return $result;
return 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;
*/
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
class ImageCommand extends Command
/**
* User "/image" command
*/
class ImageCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'image';
protected $description = 'Send Image';
protected $usage = '/image';
protected $version = '1.0.0';
protected $enabled = true;
protected $public = true;
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data = [];
$data['chat_id'] = $chat_id;
$data['caption'] = $text;
//$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;
return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
}
}
<?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.
* written by Marco Boretto <marco.bore@gmail.com>
*/
namespace Longman\TelegramBot\Commands;
*/
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
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 $description = 'Show a custom keybord with reply markup';
protected $usage = '/keyboard';
protected $version = '0.0.5';
protected $enabled = true;
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Press a Button:';
#$data['reply_to_message_id'] = $message_id;
#Keyboard examples
$keyboards = array();
//Keyboard examples
$keyboards = [];
//0
$keyboard[] = ['7','8','9'];
......@@ -64,7 +62,6 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard;
unset($keyboard);
//2
$keyboard[] = ['A'];
$keyboard[] = ['B'];
......@@ -73,8 +70,6 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard;
unset($keyboard);
//3
$keyboard[] = ['A'];
$keyboard[] = ['B'];
......@@ -83,8 +78,7 @@ class KeyboardCommand extends Command
$keyboards[] = $keyboard;
unset($keyboard);
$reply_keyboard_markup = new ReplyKeyboardMarkup(
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboards[1] ,
'resize_keyboard' => true,
......@@ -92,10 +86,7 @@ class KeyboardCommand extends Command
'selective' => false
]
);
#echo $json;
$data['reply_markup'] = $reply_keyboard_markup;
$result = Request::sendMessage($data);
return $result;
return Request::sendMessage($data);
}
}
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