Commit 6dd9459d authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

#30 Telegram bot - Support images

parent 392f49e8
......@@ -30,6 +30,7 @@
use Formapro\TelegramBot\Bot;
use Formapro\TelegramBot\Update;
use Formapro\TelegramBot\SendMessage;
use Formapro\TelegramBot\SendPhoto;
use Formapro\TelegramBot\AnswerCallbackQuery;
use Formapro\TelegramBot\InlineKeyboardButton;
use Formapro\TelegramBot\InlineKeyboardMarkup;
......@@ -71,6 +72,8 @@ class TelegramBot
private $inline_buttons = array();
private $images = array();
/**
* Initialize local properties
*/
......@@ -111,6 +114,9 @@ class TelegramBot
if(isset($a['menu'])) {
$response .= PHP_EOL . PHP_EOL . $this->MenuLookup($a['menu']);
}
if(isset($a['images']) && is_array($a['images'])) {
$this->images = $a['images'];
}
}
}
return $response? $response : $boh;
......@@ -152,28 +158,36 @@ class TelegramBot
$fullname = "$firstname $lastname";
// lookup
$response = $this->ActionLookup($text);
// variables replacements
$response = str_replace('%NAME%', $fullname, $response);
//$msg = new SendMessage($id,"Hi there $fullname ($id - $username)!");
//$bot->sendMessage($msg);
$msg = new SendMessage($id,$response);
// request phone
/*
$button = new KeyboardButton('Telefono');
$button->setRequestContact(true);
$keyboard = new ReplyKeyboardMarkup([[$button]]);
$keyboard->setOneTimeKeyboard(true);
*/
// Inline buttons
if(count($this->inline_buttons)>0) {
$buttons = [];
foreach($this->inline_buttons as $item) {
$buttons[] = InlineKeyboardButton::withTextAsCallbackData(strtoupper($item));
if(count($this->images)>0) {
$sendPhoto = new SendPhoto($id,$this->images[array_rand($this->images)]);
$sendPhoto->setCaption($response);
$bot->sendPhoto($sendPhoto);
$this->images = [];
} else {
// variables replacements
$response = str_replace('%NAME%', $fullname, $response);
//$msg = new SendMessage($id,"Hi there $fullname ($id - $username)!");
//$bot->sendMessage($msg);
$msg = new SendMessage($id,$response);
// request phone
/*
$button = new KeyboardButton('Telefono');
$button->setRequestContact(true);
$keyboard = new ReplyKeyboardMarkup([[$button]]);
$keyboard->setOneTimeKeyboard(true);
*/
// Inline buttons
if(count($this->inline_buttons)>0) {
$buttons = [];
foreach($this->inline_buttons as $item) {
$buttons[] = InlineKeyboardButton::withTextAsCallbackData(strtoupper($item));
}
$keyboard = new InlineKeyboardMarkup([$buttons]);
$msg->setReplyMarkup($keyboard);
$this->inline_buttons = [];
}
$keyboard = new InlineKeyboardMarkup([$buttons]);
$msg->setReplyMarkup($keyboard);
$bot->sendMessage($msg);
}
$bot->sendMessage($msg);
http_response_code(200);
} else {
$bot->sendMessage($msg);
......
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