Commit 5f7ec807 authored by Armando Lüscher's avatar Armando Lüscher

Merge remote-tracking branch 'mboretto/feature/smartinterface' into conversations_code_review

* mboretto/feature/smartinterface:
  conversation as internal member

Conflicts:
	src/Commands/AdminCommands/SendtochannelCommand.php
parents 685db12e aff6c033
...@@ -30,6 +30,13 @@ class SendtochannelCommand extends AdminCommand ...@@ -30,6 +30,13 @@ class SendtochannelCommand extends AdminCommand
protected $need_mysql = true; protected $need_mysql = true;
/**#@-*/ /**#@-*/
/**
* Conversation Object
*
* @var Longman\TelegramBot\Conversation
*/
protected $conversation;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -48,9 +55,9 @@ class SendtochannelCommand extends AdminCommand ...@@ -48,9 +55,9 @@ class SendtochannelCommand extends AdminCommand
$data['chat_id'] = $chat_id; $data['chat_id'] = $chat_id;
// Conversation // Conversation
$conversation = new Conversation($user_id, $chat_id, $this->getName()); $this->conversation = new Conversation($user_id, $chat_id, $this->getName());
$session = $conversation->getData(); $session = $this->conversation->getData();
$channels = (array) $this->getConfig('your_channel'); $channels = (array) $this->getConfig('your_channel');
if (!isset($session['state'])) { if (!isset($session['state'])) {
...@@ -63,9 +70,8 @@ class SendtochannelCommand extends AdminCommand ...@@ -63,9 +70,8 @@ class SendtochannelCommand extends AdminCommand
case -1: case -1:
// getConfig has not been configured asking for channel to administer // getConfig has not been configured asking for channel to administer
if ($type != 'Message' || empty($text)) { if ($type != 'Message' || empty($text)) {
$session['state'] = -1;
$session['state'] = '-1'; $this->conversation->update($session);
$conversation->update($session);
$data['text'] = 'Insert the channel name: (@yourchannel)'; $data['text'] = 'Insert the channel name: (@yourchannel)';
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]); $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
...@@ -83,8 +89,8 @@ class SendtochannelCommand extends AdminCommand ...@@ -83,8 +89,8 @@ class SendtochannelCommand extends AdminCommand
case 0: case 0:
// getConfig has been configured choose channel // getConfig has been configured choose channel
if ($type != 'Message' || !in_array($text, $channels)) { if ($type != 'Message' || !in_array($text, $channels)) {
$session['state'] = '0'; $session['state'] = 0;
$conversation->update($session); $this->conversation->update($session);
$keyboard = []; $keyboard = [];
foreach ($channels as $channel) { foreach ($channels as $channel) {
...@@ -114,7 +120,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -114,7 +120,7 @@ class SendtochannelCommand extends AdminCommand
insert: insert:
if ($session['last_message_id'] == $message->getMessageId() || ($type == 'Message' && empty($text))) { if ($session['last_message_id'] == $message->getMessageId() || ($type == 'Message' && empty($text))) {
$session['state'] = 1; $session['state'] = 1;
$conversation->update($session); $this->conversation->update($session);
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]); $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$data['text'] = 'Insert the content you want to share: text, photo, audio...'; $data['text'] = 'Insert the content you want to share: text, photo, audio...';
...@@ -129,7 +135,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -129,7 +135,7 @@ class SendtochannelCommand extends AdminCommand
case 2: case 2:
if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) { if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
$session['state'] = 2; $session['state'] = 2;
$conversation->update($session); $this->conversation->update($session);
// Execute this just with object that allow caption // Execute this just with object that allow caption
if ($session['message_type'] == 'Video' || $session['message_type'] == 'Photo') { if ($session['message_type'] == 'Video' || $session['message_type'] == 'Photo') {
...@@ -161,7 +167,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -161,7 +167,7 @@ class SendtochannelCommand extends AdminCommand
case 3: case 3:
if (($session['last_message_id'] == $message->getMessageId() || $type != 'Message' ) && $session['set_caption']) { if (($session['last_message_id'] == $message->getMessageId() || $type != 'Message' ) && $session['set_caption']) {
$session['state'] = 3; $session['state'] = 3;
$conversation->update($session); $this->conversation->update($session);
$data['text'] = 'Insert caption:'; $data['text'] = 'Insert caption:';
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]); $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
...@@ -173,8 +179,8 @@ class SendtochannelCommand extends AdminCommand ...@@ -173,8 +179,8 @@ class SendtochannelCommand extends AdminCommand
// no break // no break
case 4: case 4:
if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) { if ($session['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
$session['state'] = '4'; $session['state'] = 4;
$conversation->update($session); $this->conversation->update($session);
$data['text'] = 'Message will look like this:'; $data['text'] = 'Message will look like this:';
$result = Request::sendMessage($data); $result = Request::sendMessage($data);
...@@ -211,7 +217,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -211,7 +217,7 @@ class SendtochannelCommand extends AdminCommand
$session['last_message_id'] = $message->getMessageId(); $session['last_message_id'] = $message->getMessageId();
// no break // no break
case 5: case 5:
$conversation->stop(); $this->conversation->stop();
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]); $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
if ($session['post_message']) { if ($session['post_message']) {
......
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