Skip to content

Bots 2.0 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions examples/Commands/InlinekeyboardCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
*
* 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'
]
];
$inline_keyboard[] = [
[
'text' => 'send callback query',
'callback_data' => 'thumb up'
],
[
'text' => 'send callback query (no alert)',
'callback_data' => 'thumb down'
]
];

$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);

$data['reply_markup'] = new InlineKeyboardMarkup(
[
'inline_keyboard' => $inline_keyboards[3],
]
);

return Request::sendMessage($data);
}
}
19 changes: 17 additions & 2 deletions examples/Commands/KeyboardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/**#@-*/

/**
Expand All @@ -49,7 +49,7 @@ public function execute()
$keyboard[] = ['4','5','6'];
$keyboard[] = ['1','2','3'];
$keyboard[] = [' ','0',' '];

$keyboards[] = $keyboard;
unset($keyboard);

Expand Down Expand Up @@ -78,6 +78,21 @@ public function execute()
$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] ,
Expand Down
51 changes: 51 additions & 0 deletions src/Commands/SystemCommands/CallbackqueryCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
*
* 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();
$callback_data = $callback_query->getData();

$data['callback_query_id'] = $callback_query_id;

if ($callback_data == 'thumb up') {
$data['text'] = 'Hello World!';
$data['show_alert'] = true;
} else {
$data['text'] = 'Hello World!';
$data['show_alert'] = false;
}

return Request::answerCallbackQuery($data);
}
}
6 changes: 3 additions & 3 deletions src/Commands/SystemCommands/InlinequeryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function execute()
$data = ['inline_query_id' => $inline_query->getId()];

$articles = [
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
];

$array_article = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
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';
/**#@-*/

Expand All @@ -31,6 +31,6 @@ class LeftchatparticipantCommand extends SystemCommand
/*public function execute()
{
//$message = $this->getMessage();
//$participant = $message->getLeftChatParticipant();
//$member = $message->getLeftChatMember();
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
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';
/**#@-*/

Expand All @@ -34,12 +34,12 @@ public function execute()
$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 = [
Expand Down
1 change: 1 addition & 0 deletions src/Commands/UserCommands/SurveyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* 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\Request;
Expand Down
1 change: 0 additions & 1 deletion src/Commands/UserCommands/WhoamiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function execute()
if ($ServerResponse->isOk()) {
Request::downloadFile($ServerResponse->getResult());
}

} else {
//No Photo just send text
$data['text'] = $caption;
Expand Down
1 change: 0 additions & 1 deletion src/ConversationDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static function selectConversation($user_id, $chat_id, $limit = null)
$sth->execute();

$results = $sth->fetchAll(\PDO::FETCH_ASSOC);

} catch (\Exception $e) {
throw new TelegramException($e->getMessage());
}
Expand Down
Loading