Commit 84a16d4c authored by MBoretto's avatar MBoretto

Introducing ReplyMakup.php Class and some usage example

parent dc174281
......@@ -14,7 +14,8 @@ A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.or
## introduction
This is a pure php Telegram Bot, fully extensible via plugins. Telegram recently announced official support for a [Bot API](https://telegram.org/blog/bot-revolution) allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one could simply write a plugin and have interactions in a matter of minutes.
This is a pure php Telegram Bot, fully extensible via plugins. Telegram recently announced official support for a [Bot API](https://telegram.org/blog/bot-revolution) allowing integrators of all sorts to bring automated interactions to the mobile platform. This Bot aims to provide a platform where one could simply write a plugin and have interactions in a matter of minutes.
The Bot support Reply Markup and handle commands in the group chat.
Instructions
......
<?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;
use Longman\TelegramBot\Entities\ReplyMarkup;
class ForceReplyCommand extends Command
{
protected $name = 'forcereply';
protected $description = 'Force reply with reply markup';
protected $usage = '/forcereply';
protected $version = '0.0.5';
protected $enabled = true;
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['chat_id'] = $chat_id;
$data['text'] = 'Write something:';
#$data['reply_to_message_id'] = $message_id;
$markup = new ReplyMarkup;
//$markup->addForceReply($selective = false)
$markup->addForceReply(false);
$json = $markup->getJsonQuery();
$data['reply_markup'] = $json;
$result = Request::sendMessage($data);
return $result;
}
}
<?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;
use Longman\TelegramBot\Entities\ReplyMarkup;
class HidekeyboardCommand extends Command
{
protected $name = 'hidekeyboard';
protected $description = 'Hide the custom keyboard';
protected $usage = '/hidekeyboard';
protected $version = '0.0.5';
protected $enabled = true;
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['chat_id'] = $chat_id;
$data['text'] = 'Keyboard Hided';
#$data['reply_to_message_id'] = $message_id;
$markup = new ReplyMarkup;
//$markup->addKeyBoardHide($selective = false){
$markup->addKeyBoardHide(false);
$json = $markup->getJsonQuery();
$data['reply_markup'] = $json;
$result = Request::sendMessage($data);
return $result;
}
}
<?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;
use Longman\TelegramBot\Entities\ReplyMarkup;
class KeyboardCommand extends Command
{
protected $name = 'keyboard';
protected $description = 'Show a custom keybord with reply markup';
protected $usage = '/keyboard';
protected $version = '0.0.5';
protected $enabled = true;
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['chat_id'] = $chat_id;
$data['text'] = 'Press a Button:';
#$data['reply_to_message_id'] = $message_id;
$markup = new ReplyMarkup;
//$markup->addKeyBoard($options,$resize=false,$once=false,$selective=false)
//onother keyboard example
#$markup->addKeyBoard(array('A','B','C'),true,false,false);
//onother keyboard example
#$markup->addKeyBoard(array('A',array('B','B1'),'C'),true,false,false);
$markup->addKeyBoard(array(
array('7','8','9'),
array('4','5','6'),
array('1','2','3'),
array('0')
), true, false, false);
$json = $markup->getJsonQuery();
$data['reply_markup'] = $json;
$result = Request::sendMessage($data);
return $result;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class ReplyMarkup extends Entity
{
protected $reply_markup_array;
public function __construct()
{
$this->reply_markup_array = array();
}
public function addKeyBoard($options, $resize = false, $once = false, $selective = false)
{
if (is_array($options)) {
$list = array();
foreach ($options as $item) {
if (is_array($item)) {
$list[] = $item;
} else {
$list[] = array($item);
}
}
$this->reply_markup_array['keyboard'] = $list;
if ($resize == true) {
$this->reply_markup_array['resize_keyboard'] = true;
}
if ($once == true) {
$this->reply_markup_array['one_time_keyboard'] = true;
}
$this->addSelective($selective);
return true;
}
return false;
}
public function addKeyBoardHide($selective = false)
{
$this->reply_markup_array['hide_keyboard'] = true;
$this->addSelective($selective);
}
public function addForceReply($selective = false)
{
$this->reply_markup_array['force_reply'] = true;
$this->addSelective($selective);
}
protected function addSelective($selective = false)
{
if ($selective == true) {
$this->reply_markup_array['selective'] = true;
}
}
public function getJsonQuery()
{
return json_encode($this->reply_markup_array);
}
}
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