Commit d4ccf64b authored by Jack'lul's avatar Jack'lul

bots 2.0 - applied some of the changes introduced in this update

parent 11cbd79a
<?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\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
/**
* User "/inlinekeyboard" command
*/
class InlinekeyboardCommand extends UserCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'inlinekeyboard';
protected $description = 'Show a custom inline keybord with reply markup';
protected $usage = '/inlinekeyboard';
protected $version = '0.0.1';
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = [];
$data['chat_id'] = $chat_id;
$data['text'] = 'Press a Button:';
//Keyboard examples
$inline_keyboards = [];
//0
$inline_keyboard[] = [
[
'text' => '<',
'callback_data' => 'go_left'
],
[
'text' => '^',
'callback_data' => 'go_up'
],
[
'text' => '>',
'callback_data' => 'go_right'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//1
$inline_keyboard[] = [
[
'text' => 'open google.com',
'url' => 'google.com'
],
[
'text' => 'open youtube.com',
'url' => 'youtube.com'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//2
$inline_keyboard[] = [
[
'text' => 'search \'test\' inline',
'switch_inline_query' => 'test'
],
[
'text' => 'search \'cats\' inline',
'switch_inline_query' => 'cats'
]
];
$inline_keyboard[] = [
[
'text' => 'search \'earth\' inline',
'switch_inline_query' => 'earth'
],
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//3
$inline_keyboard[] = [
[
'text' => 'open url',
'url' => 'https://github.com/akalongman/php-telegram-bot'
]
];
$inline_keyboard[] = [
[
'text' => 'switch to inline',
'switch_inline_query' => 'thumb up'
],
[
'text' => 'send callback query',
'callback_data' => 'thumb up'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
$data['reply_markup'] = new InlineKeyboardMarkup(
[
'inline_keyboard' => $inline_keyboards[3],
]
);
return Request::sendMessage($data);
}
}
......@@ -25,7 +25,7 @@ class KeyboardCommand extends UserCommand
protected $name = 'keyboard';
protected $description = 'Show a custom keybord with reply markup';
protected $usage = '/keyboard';
protected $version = '0.0.5';
protected $version = '0.0.6';
/**#@-*/
/**
......@@ -49,7 +49,7 @@ class KeyboardCommand extends UserCommand
$keyboard[] = ['4','5','6'];
$keyboard[] = ['1','2','3'];
$keyboard[] = [' ','0',' '];
$keyboards[] = $keyboard;
unset($keyboard);
......@@ -78,6 +78,21 @@ class KeyboardCommand extends UserCommand
$keyboards[] = $keyboard;
unset($keyboard);
//4 (bots 2.0)
$keyboard[] = [
[
'text' => 'request_contact',
'request_contact' => true
],
[
'text' => 'request_location',
'request_location' => true
]
];
$keyboards[] = $keyboard;
unset($keyboard);
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboards[1] ,
......
<?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\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* Callback query command
*/
class CallbackqueryCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'callbackquery';
protected $description = 'Reply to callback query';
protected $version = '1.0.0';
/**#@-*/
/**
* {@inheritdoc}
*/
public function execute()
{
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$callback_query_id = $callback_query->getId();
$data['callback_query_id'] = $callback_query_id;
$data['text'] = 'Hello world!';
$data['show_alert'] = true;
return Request::answerCallbackQuery($data);
}
}
......@@ -13,15 +13,15 @@ namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
/**
* Left chat participant command
* Left chat member command
*/
class LeftchatparticipantCommand extends SystemCommand
class LeftchatmemberCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'leftchatparticipant';
protected $description = 'Left Chat Participant';
protected $name = 'Leftchatmember';
protected $description = 'Left Chat Member';
protected $version = '1.0.1';
/**#@-*/
......@@ -31,6 +31,6 @@ class LeftchatparticipantCommand extends SystemCommand
/*public function execute()
{
//$message = $this->getMessage();
//$participant = $message->getLeftChatParticipant();
//$member = $message->getLeftChatMember();
}*/
}
......@@ -14,15 +14,15 @@ use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/**
* New chat participant command
* New chat member command
*/
class NewchatparticipantCommand extends SystemCommand
class NewchatmemberCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
*/
protected $name = 'Newchatparticipant';
protected $description = 'New Chat Participant';
protected $name = 'Newchatmember';
protected $description = 'New Chat Member';
protected $version = '1.0.1';
/**#@-*/
......@@ -34,12 +34,12 @@ class NewchatparticipantCommand extends SystemCommand
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$participant = $message->getNewChatParticipant();
$member = $message->getNewChatMember();
if (strtolower($participant->getUsername()) === strtolower($this->getTelegram()->getBotName())) {
if ($message->botAddedInChat()) {
$text = 'Hi there!';
} else {
$text = 'Hi ' . $participant->tryMention() . '!';
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
......
This diff is collapsed.
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class CallbackQuery extends Entity
{
protected $id;
protected $from;
protected $message;
protected $inline_message_id;
protected $data;
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->from = isset($data['from']) ? $data['from'] : null;
if (empty($this->from)) {
throw new TelegramException('from is empty!');
}
$this->from = new User($this->from);
$this->message = isset($data['message']) ? $data['message'] : null;
if (!empty($this->message)) {
$this->message = new Message($this->message, $this->getBotName());
}
$this->inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
$this->data = isset($data['data']) ? $data['data'] : null;
if (empty($this->data)) {
throw new TelegramException('data is empty!');
}
}
public function getId()
{
return $this->id;
}
public function getFrom()
{
return $this->from;
}
public function getMessage()
{
return $this->message;
}
public function getInlineMessageId()
{
return $this->inline_message_id;
}
public function getData()
{
return $this->data;
}
}
......@@ -17,6 +17,8 @@ class ChosenInlineResult extends Entity
protected $result_id;
protected $from;
protected $location;
protected $inline_message_id;
protected $query;
public function __construct(array $data)
......@@ -33,8 +35,13 @@ class ChosenInlineResult extends Entity
}
$this->from = new User($this->from);
$this->location = isset($data['location']) ? $data['location'] : null;
if (!empty($this->location)) {
$this->location = new Location($this->location);
}
$this->inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
$this->query = isset($data['query']) ? $data['query'] : null;
$this->offset = isset($data['offset']) ? $data['offset'] : null;
}
public function getResultId()
......@@ -46,6 +53,17 @@ class ChosenInlineResult extends Entity
{
return $this->from;
}
public function getLocation()
{
return $this->location;
}
public function getInlineMessageId()
{
return $this->inline_message_id;
}
public function getQuery()
{
return $this->query;
......
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineKeyboardMarkup extends Entity
{
protected $inline_keyboard;
/*
* @todo: check for InlineKeyboardButton elements
*/
public function __construct($data = array())
{
if (isset($data['inline_keyboard'])) {
if (is_array($data['inline_keyboard'])) {
foreach ($data['inline_keyboard'] as $item) {
if (!is_array($item)) {
throw new TelegramException('Inline Keyboard subfield is not an array!');
}
}
$this->inline_keyboard = $data['inline_keyboard'];
} else {
throw new TelegramException('Inline Keyboard field is not an array!');
}
} else {
throw new TelegramException('Inline Keyboard field is empty!');
}
}
}
......@@ -17,6 +17,7 @@ class InlineQuery extends Entity
protected $id;
protected $from;
protected $location;
protected $query;
protected $offset;
......@@ -34,6 +35,11 @@ class InlineQuery extends Entity
}
$this->from = new User($this->from);
$this->location = isset($data['location']) ? $data['location'] : null;
if (!empty($this->location)) {
$this->location = new Location($this->location);
}
$this->query = isset($data['query']) ? $data['query'] : null;
$this->offset = isset($data['offset']) ? $data['offset'] : null;
}
......@@ -42,11 +48,14 @@ class InlineQuery extends Entity
{
return $this->id;
}
public function getFrom()
{
return $this->from;
}
public function getLocation()
{
return $this->location;
}
public function getQuery()
{
return $this->query;
......@@ -55,4 +64,5 @@ class InlineQuery extends Entity
{
return $this->offset;
}
}
......@@ -16,9 +16,8 @@ class InlineQueryResult extends Entity
{
protected $type;
protected $id;
protected $title;
protected $parse_mode;
protected $disable_web_page_preview;
protected $input_message_content;
protected $reply_markup;
public function __construct(array $data)
{
......@@ -28,13 +27,8 @@ class InlineQueryResult extends Entity
throw new TelegramException('id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->disable_web_page_preview = isset($data['disable_webpage_preview']) ? $data['disable_webpage_preview'] : null;
$this->parse_mode = isset($data['parse_mode']) ? $data['parse_mode'] : null;
$this->input_message_content = isset($data['input_message_content']) ? $data['input_message_content'] : null;
$this->reply_markup = isset($data['reply_markup']) ? $data['reply_markup'] : null;
}
public function getType()
......@@ -46,18 +40,6 @@ class InlineQueryResult extends Entity
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function getParseMode()
{
return $this->parse_mode;
}
public function getDisableWebPagePreview()
{
return $this->disable_web_page_preview;
}
}
......@@ -14,7 +14,8 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultArticle extends InlineQueryResult
{
protected $message_text;
protected $title;
protected $input_message_content;
protected $url;
protected $hide_url;
protected $description;
......@@ -28,9 +29,14 @@ class InlineQueryResultArticle extends InlineQueryResult
$this->type = 'article';
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
if (empty($this->message_text)) {
throw new TelegramException('message_text is empty!');
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->input_message_content = isset($data['input_message_content']) ? $data['input_message_content'] : null;
if (empty($this->input_message_content)) {
throw new TelegramException('input_message_content is empty!');
}
$this->url = isset($data['url']) ? $data['url'] : null;
......@@ -42,9 +48,14 @@ class InlineQueryResultArticle extends InlineQueryResult
}
public function getMessageText()
public function getTitle()
{
return $this->title;
}
public function getInputMessageContent()
{
return $this->message_text;
return $this->input_message_content;
}
public function getUrl()
......@@ -76,4 +87,5 @@ class InlineQueryResultArticle extends InlineQueryResult
{
return $this->thumb_height;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultAudio extends InlineQueryResult
{
protected $audio_url;
protected $title;
protected $performer;
protected $audio_duration;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'audio';
$this->audio_url = isset($data['audio_url']) ? $data['audio_url'] : null;
if (empty($this->audio_url)) {
throw new TelegramException('audio_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->performer = isset($data['performer']) ? $data['performer'] : null;
$this->audio_duration = isset($data['audio_duration']) ? $data['audio_duration'] : null;
}
public function getAudioUrl()
{
return $this->audio_url;
}
public function getTitle()
{
return $this->title;
}
public function getPerformer()
{
return $this->performer;
}
public function getAudioDuration()
{
return $this->audio_duration;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultContact extends InlineQueryResult
{
protected $phone_number;
protected $first_name;
protected $last_name;
protected $thumb_url;
protected $thumb_width;
protected $thumb_height;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'contact';
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
}
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
if (empty($this->first_name)) {
throw new TelegramException('first_name is empty!');
}
$this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
public function getPhoneNumber()
{
return $this->phone_number;
}
public function getFirstName()
{
return $this->first_name;
}
public function getLastName()
{
return $this->last_name;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getThumbWidth()
{
return $this->thumb_width;
}
public function getThumbHeight()
{
return $this->thumb_height;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultDocument extends InlineQueryResult
{
protected $title;
protected $caption;
protected $document_url;
protected $mime_type;
protected $description;
protected $thumb_url;
protected $thumb_width;
protected $thumb_height;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'document';
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->document_url = isset($data['document_url']) ? $data['document_url'] : null;
if (empty($this->document_url)) {
throw new TelegramException('document_url is empty!');
}
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
if (empty($this->mime_type)) {
throw new TelegramException('mime_type is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
}
public function getDocumentUrl()
{
return $this->document_url;
}
public function getMimeType()
{
return $this->mime_type;
}
public function getDescription()
{
return $this->description;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getThumbWidth()
{
return $this->thumb_width;
}
public function getThumbHeight()
{
return $this->thumb_height;
}
}
......@@ -19,6 +19,7 @@ class InlineQueryResultGif extends InlineQueryResult
protected $gif_width;
protected $gif_height;
protected $thumb_url;
protected $title;
protected $caption;
protected $message_text;
......@@ -41,10 +42,10 @@ class InlineQueryResultGif extends InlineQueryResult
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
}
public function getGifUrl()
......@@ -63,6 +64,10 @@ class InlineQueryResultGif extends InlineQueryResult
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
......
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultLocation extends InlineQueryResult
{
protected $latitude;
protected $longitude;
protected $title;
protected $thumb_url;
protected $thumb_width;
protected $thumb_height;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'location';
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
public function getLatitude()
{
return $this->latitude;
}
public function getLongitude()
{
return $this->longitude;
}
public function getTitle()
{
return $this->title;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getThumbWidth()
{
return $this->thumb_width;
}
public function getThumbHeight()
{
return $this->thumb_height;
}
}
......@@ -19,6 +19,7 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
protected $mpeg4_width;
protected $mpeg4_height;
protected $thumb_url;
protected $title;
protected $caption;
protected $message_text;
......@@ -41,6 +42,7 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
......@@ -62,6 +64,10 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
......
......@@ -19,9 +19,9 @@ class InlineQueryResultPhoto extends InlineQueryResult
protected $photo_width;
protected $photo_height;
protected $thumb_url;
protected $title;
protected $description;
protected $caption;
protected $message_text;
public function __construct(array $data)
{
......@@ -29,7 +29,6 @@ class InlineQueryResultPhoto extends InlineQueryResult
$this->type = 'photo';
$this->photo_url = isset($data['photo_url']) ? $data['photo_url'] : null;
if (empty($this->photo_url)) {
throw new TelegramException('photo_url is empty!');
......@@ -42,9 +41,10 @@ class InlineQueryResultPhoto extends InlineQueryResult
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
}
......@@ -64,6 +64,10 @@ class InlineQueryResultPhoto extends InlineQueryResult
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
......@@ -72,8 +76,4 @@ class InlineQueryResultPhoto extends InlineQueryResult
{
return $this->caption;
}
public function getMessageText()
{
return $this->message_text;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVenue extends InlineQueryResult
{
protected $latitude;
protected $longitude;
protected $title;
protected $address;
protected $foursquare_id;
protected $thumb_url;
protected $thumb_width;
protected $thumb_height;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'venue';
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->address = isset($data['address']) ? $data['address'] : null;
if (empty($this->address)) {
throw new TelegramException('address is empty!');
}
$this->foursquare_id = isset($data['foursquare_id']) ? $data['foursquare_id'] : null;
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
public function getLatitude()
{
return $this->latitude;
}
public function getLongitude()
{
return $this->longitude;
}
public function getTitle()
{
return $this->title;
}
public function getAddress()
{
return $this->address;
}
public function getFoursquareId()
{
return $this->foursquare_id;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getThumbWidth()
{
return $this->thumb_width;
}
public function getThumbHeight()
{
return $this->thumb_height;
}
}
......@@ -17,10 +17,13 @@ class InlineQueryResultVideo extends InlineQueryResult
protected $video_url;
protected $mime_type;
protected $message_text;
protected $thumb_url;
protected $title;
protected $caption;
protected $video_width;
protected $video_height;
protected $video_duration;
protected $description;
public function __construct(array $data)
{
......@@ -36,13 +39,17 @@ class InlineQueryResultVideo extends InlineQueryResult
if (empty($this->mime_type)) {
throw new TelegramException('mime_type is empty!');
}
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
if (empty($this->message_text)) {
throw new TelegramException('message_text is empty!');
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
if (empty($this->thumb_url)) {
throw new TelegramException('thumb_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
$this->video_width = isset($data['video_width']) ? $data['video_width'] : null;
$this->video_height = isset($data['video_height']) ? $data['video_height'] : null;
$this->video_duration = isset($data['video_duration']) ? $data['video_duration'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
}
public function getVideoUrl()
......@@ -53,9 +60,17 @@ class InlineQueryResultVideo extends InlineQueryResult
{
return $this->mime_type;
}
public function getMessageText()
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->message_text;
return $this->title;
}
public function getCaption()
{
return $this->caption;
}
public function getVideoWidth()
{
......@@ -69,4 +84,8 @@ class InlineQueryResultVideo extends InlineQueryResult
{
return $this->video_duration;
}
public function getDescription()
{
return $this->description;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVoice extends InlineQueryResult
{
protected $voice_url;
protected $title;
protected $voice_duration;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'voice';
$this->voice_url = isset($data['voice_url']) ? $data['voice_url'] : null;
if (empty($this->voice_url)) {
throw new TelegramException('voice_url is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->voice_duration = isset($data['voice_duration']) ? $data['voice_duration'] : null;
}
public function getVoiceUrl()
{
return $this->voice_url;
}
public function getTitle()
{
return $this->title;
}
public function getVoiceDuration()
{
return $this->voice_duration;
}
}
......@@ -49,9 +49,11 @@ class Message extends Entity
protected $location;
protected $new_chat_participant;
protected $venue;
protected $left_chat_participant;
protected $new_chat_member;
protected $left_chat_member;
protected $new_chat_title;
......@@ -69,6 +71,9 @@ class Message extends Entity
protected $migrate_from_chat_id;
protected $pinned_message;
protected $entities;
private $command;
......@@ -180,16 +185,22 @@ class Message extends Entity
$this->type = 'Location';
}
$this->new_chat_participant = isset($data['new_chat_participant']) ? $data['new_chat_participant'] : null;
if (!empty($this->new_chat_participant)) {
$this->new_chat_participant = new User($this->new_chat_participant);
$this->type = 'new_chat_participant';
$this->venue = isset($data['venue']) ? $data['venue'] : null;
if (!empty($this->venue)) {
$this->venue = new Venue($this->venue);
$this->type = 'Venue';
}
$this->left_chat_participant = isset($data['left_chat_participant']) ? $data['left_chat_participant'] : null;
if (!empty($this->left_chat_participant)) {
$this->left_chat_participant = new User($this->left_chat_participant);
$this->type = 'left_chat_participant';
$this->new_chat_member = isset($data['new_chat_member']) ? $data['new_chat_member'] : null;
if (!empty($this->new_chat_member)) {
$this->new_chat_member = new User($this->new_chat_member);
$this->type = 'new_chat_member';
}
$this->left_chat_member = isset($data['left_chat_member']) ? $data['left_chat_member'] : null;
if (!empty($this->left_chat_member)) {
$this->left_chat_member = new User($this->left_chat_member);
$this->type = 'left_chat_member';
}
$this->new_chat_title = isset($data['new_chat_title']) ? $data['new_chat_title'] : null;
......@@ -232,11 +243,23 @@ class Message extends Entity
if ($this->migrate_to_chat_id) {
$this->type = 'migrate_to_chat_id';
}
$this->migrate_from_chat_id = isset($data['migrate_from_chat_id']) ? $data['migrate_from_chat_id'] : null;
if ($this->migrate_from_chat_id) {
$this->type = 'migrate_from_chat_id';
}
$this->pinned_message = isset($data['pinned_message']) ? $data['pinned_message'] : null;
$this->entities = isset($data['entities']) ? $data['entities'] : null;
if (!empty($this->entities)) {
foreach ($this->entities as $entity) {
if (!empty($entity)) {
$entities[] = new MessageEntity($entity);
}
}
$this->entities = $entities;
}
}
//return the entire command like /echo or /echo@bot1 if specified
......@@ -377,14 +400,19 @@ class Message extends Entity
return $this->location;
}
public function getNewChatParticipant()
public function getVenue()
{
return $this->venue;
}
public function getNewChatMember()
{
return $this->new_chat_participant;
return $this->new_chat_member;
}
public function getLeftChatParticipant()
public function getLeftChatMember()
{
return $this->left_chat_participant;
return $this->left_chat_member;
}
public function getNewChatTitle()
......@@ -392,13 +420,11 @@ class Message extends Entity
return $this->new_chat_title;
}
public function getNewChatPhoto()
{
return $this->new_chat_photo;
}
public function getDeleteChatPhoto()
{
return $this->delete_chat_photo;
......@@ -431,8 +457,8 @@ class Message extends Entity
public function botAddedInChat()
{
if (!empty($this->new_chat_participant)) {
if ($this->new_chat_participant->getUsername() == $this->getBotName()) {
if (!empty($this->new_chat_member)) {
if ($this->new_chat_member->getUsername() == $this->getBotName()) {
return true;
}
}
......@@ -444,4 +470,14 @@ class Message extends Entity
{
return $this->type;
}
public function getPinnedMessage()
{
return $this->pinned_message;
}
public function getEntities()
{
return $this->entities;
}
}
<?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\Entities;
class MessageEntity extends Entity
{
protected $type;
protected $offset;
protected $length;
protected $url;
public function __construct(array $data)
{
$this->type = isset($data['type']) ? $data['type'] : null;
if (empty($this->type)) {
throw new TelegramException('type is empty!');
}
$this->offset = isset($data['offset']) ? $data['offset'] : null;
if (empty($this->offset) && $this->offset != 0) { // @todo:this is not an ideal solution?
throw new TelegramException('offset is empty!');
}
$this->length = isset($data['length']) ? $data['length'] : null;
if (empty($this->length) && $this->offset != 0) { // @todo this is not an ideal solution?
throw new TelegramException('length is empty!');
}
$this->url = isset($data['url']) ? $data['url'] : null;
}
public function getType()
{
return $this->type;
}
public function getOffset()
{
return $this->offset;
}
public function getLength()
{
return $this->length;
}
public function getUrl()
{
return $this->url;
}
}
......@@ -19,6 +19,8 @@ class Update extends Entity
protected $message;
protected $inline_query;
protected $chosen_inline_result;
protected $callback_query;
private $update_type;
public function __construct(array $data, $bot_name)
......@@ -44,11 +46,18 @@ class Update extends Entity
$this->inline_query = new InlineQuery($this->inline_query);
$this->update_type = 'inline_query';
}
$this->chosen_inline_result = isset($data['chosen_inline_result']) ? $data['chosen_inline_result'] : null;
if (!empty($this->chosen_inline_result)) {
$this->chosen_inline_result = new ChosenInlineResult($this->chosen_inline_result);
$this->update_type = 'chosen_inline_result';
}
$this->callback_query = isset($data['callback_query']) ? $data['callback_query'] : null;
if (!empty($this->callback_query)) {
$this->callback_query = new CallbackQuery($this->callback_query);
$this->update_type = 'callback_query';
}
}
public function getUpdateId()
......@@ -64,6 +73,10 @@ class Update extends Entity
{
return $this->inline_query;
}
public function getCallbackQuery()
{
return $this->callback_query;
}
public function getChosenInlineResult()
{
return $this->chosen_inline_result;
......@@ -80,6 +93,8 @@ class Update extends Entity
return $this->getInlineQuery();
} elseif ($this->update_type == 'chosen_inline_result') {
return $this->getChosenInlineResult();
} elseif ($this->update_type == 'callback_query') {
return $this->getCallbackQuery();
}
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class Venue extends Entity
{
protected $location;
protected $latitude;
protected $longitude;
protected $title;
protected $address;
protected $foursquare_id;
public function __construct(array $data)
{
$this->location = isset($data['location']) ? $data['location'] : null;
$this->latitude = isset($data['latitude']) ? $data['latitude'] : null;
$this->longitude = isset($data['longitude']) ? $data['longitude'] : null;
// Venue can either contain location object or just latitude and longitude fields, check accordingly
if (!empty($this->location)) {
$this->location = new Location($this->location);
} else {
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
}
if (empty($this->longitude)) {
throw new TelegramException('longitude is empty!');
}
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->address = isset($data['address']) ? $data['address'] : null;
if (empty($this->address)) {
throw new TelegramException('address is empty!');
}
$this->foursquare_id = isset($data['foursquare_id']) ? $data['foursquare_id'] : null;
}
public function getLocation()
{
return $this->location;
}
public function getLongitude()
{
return $this->longitude;
}
public function getLatitude()
{
return $this->latitude;
}
public function getTitle()
{
return $this->title;
}
public function getAddress()
{
return $this->address;
}
public function getFoursquareId()
{
return $this->foursquare_id;
}
}
......@@ -38,6 +38,8 @@ class Request
* @var array
*/
private static $methods = [
'getUpdates',
'setWebhook',
'getMe',
'sendMessage',
'forwardMessage',
......@@ -48,11 +50,14 @@ class Request
'sendVideo',
'sendVoice',
'sendLocation',
'sendVenue',
'sendContact',
'sendChatAction',
'getUserProfilePhotos',
'getUpdates',
'setWebhook',
'getFile',
'kickChatMember',
'unbanChatMember',
'answerCallbackQuery',
'answerInlineQuery',
];
......@@ -513,6 +518,38 @@ class Request
return self::send('sendLocation', $data);
}
/**
* Send venue
*
* @param array $data
*
* @return mixed
*/
public static function sendVenue(array $data)
{
if (empty($data)) {
throw new TelegramException('Data is empty!');
}
return self::send('sendVenue', $data);
}
/**
* Send contact
*
* @param array $data
*
* @return mixed
*/
public static function sendContact(array $data)
{
if (empty($data)) {
throw new TelegramException('Data is empty!');
}
return self::send('sendContact', $data);
}
/**
* Send chat action
*
......@@ -596,6 +633,54 @@ class Request
return self::send('getFile', $data);
}
/**
* Kick Chat Member
*
* @param array $data
*
* @return mixed
*/
public static function kickChatMember(array $data)
{
if (empty($data)) {
throw new TelegramException('Data is empty!');
}
return self::send('kickChatMember', $data);
}
/**
* Unban Chat Member
*
* @param array $data
*
* @return mixed
*/
public static function unbanChatMember(array $data)
{
if (empty($data)) {
throw new TelegramException('Data is empty!');
}
return self::send('unbanChatMember', $data);
}
/**
* Answer callback query
*
* @param array $data
*
* @return mixed
*/
public static function answerCallbackQuery(array $data)
{
if (empty($data)) {
throw new TelegramException('Data is empty!');
}
return self::send('answerCallbackQuery', $data);
}
/**
* Answer inline query
*
......
......@@ -448,7 +448,7 @@ class Telegram
$command = 'genericmessage';
$update_type = $this->update->getUpdateType();
if (in_array($update_type, ['inline_query', 'chosen_inline_result'])) {
if (in_array($update_type, ['inline_query', 'chosen_inline_result', 'callback_query'])) {
$command = $this->getCommandFromType($update_type);
} elseif ($update_type === 'message') {
$message = $this->update->getMessage();
......@@ -467,10 +467,10 @@ class Telegram
'channel_chat_created',
'delete_chat_photo',
'group_chat_created',
'left_chat_participant',
'left_chat_member',
'migrate_from_chat_id',
'migrate_to_chat_id',
'new_chat_participant',
'new_chat_member',
'new_chat_photo',
'new_chat_title',
'supergroup_chat_created',
......
......@@ -30,10 +30,10 @@ CREATE TABLE IF NOT EXISTS `user_chat` (
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `inline_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query.',
`user_id` bigint NULL COMMENT 'Sender',
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location of the sender',
`query` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Text of the query',
`offset` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Offset of the result',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
......@@ -49,6 +49,8 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_query` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for chosen query.',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Id of the chosen result',
`user_id` bigint NULL COMMENT 'Sender',
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location object, senders\'s location.',
`inline_message_id` bigint NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
`query` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Text of the query',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
......@@ -59,6 +61,21 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_query` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `callback_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query.',
`user_id` bigint NULL COMMENT 'Sender',
`message` TEXT NULL DEFAULT NULL COMMENT 'Message',
`inline_message_id` bigint NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
`data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button.',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`)
REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `message` (
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Chat identifier.',
`id` bigint UNSIGNED COMMENT 'Unique message identifier',
......@@ -78,8 +95,9 @@ CREATE TABLE IF NOT EXISTS `message` (
`caption` TEXT DEFAULT NULL COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`contact` TEXT DEFAULT NULL COMMENT 'Contact object. Message is a shared contact, information about the contact',
`location` TEXT DEFAULT NULL COMMENT 'Location object. Message is a shared location, information about the location',
`new_chat_participant` bigint NULL DEFAULT NULL COMMENT 'User id. A new member was added to the group, information about them (this member may be bot itself)',
`left_chat_participant` bigint NULL DEFAULT NULL COMMENT 'User id. A member was removed from the group, information about them (this member may be bot itself)',
`venue` TEXT DEFAULT NULL COMMENT 'Venue object. Message is a Venue, information about the Venue',
`new_chat_member` bigint NULL DEFAULT NULL COMMENT 'User id. A new member was added to the group, information about them (this member may be bot itself)',
`left_chat_member` bigint NULL DEFAULT NULL COMMENT 'User id. A member was removed from the group, information about them (this member may be bot itself)',
`new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A group title was changed to this value',
`new_chat_photo` TEXT DEFAULT NULL COMMENT 'Array of PhotoSize objects. A group photo was change to this value',
`delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group photo was deleted',
......@@ -93,8 +111,8 @@ CREATE TABLE IF NOT EXISTS `message` (
KEY `forward_from` (`forward_from`),
KEY `reply_to_chat` (`reply_to_chat`),
KEY `reply_to_message` (`reply_to_message`),
KEY `new_chat_participant` (`new_chat_participant`),
KEY `left_chat_participant` (`left_chat_participant`),
KEY `new_chat_member` (`new_chat_member`),
KEY `left_chat_member` (`left_chat_member`),
KEY `migrate_from_chat_id` (`migrate_from_chat_id`),
KEY `migrate_to_chat_id` (`migrate_to_chat_id`),
......@@ -103,27 +121,29 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`,`id`),
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`new_chat_participant`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_participant`) REFERENCES `user` (`id`)
FOREIGN KEY (`new_chat_member`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `telegram_update` (
`id` bigint UNSIGNED COMMENT 'The update\'s unique identifier.',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Chat identifier.',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The query unique identifier.',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The inline query unique identifier.',
`chosen_inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The chosen query unique identifier.',
`callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The callback query unique identifier.',
PRIMARY KEY (`id`),
KEY `message_id` (`chat_id`, `message_id`),
KEY `inline_query_id` (`inline_query_id`),
KEY `chosen_inline_query_id` (`chosen_inline_query_id`),
KEY `callback_query_id` (`callback_query_id`),
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`,`id`),
FOREIGN KEY (`inline_query_id`) REFERENCES `inline_query` (`id`),
FOREIGN KEY (`chosen_inline_query_id`) REFERENCES `chosen_inline_query` (`id`)
FOREIGN KEY (`chosen_inline_query_id`) REFERENCES `chosen_inline_query` (`id`),
FOREIGN KEY (`callback_query_id`) REFERENCES `callback_query` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `conversation` (
......
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