From 4c0c6917bc51fba6ae04f02be2c88cd573a79383 Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Mon, 31 Aug 2020 03:13:25 -0400 Subject: [PATCH] fix #14 --- bootstrap/bootstrap.php | 50 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/bootstrap/bootstrap.php b/bootstrap/bootstrap.php index 6e45483..fa9582c 100644 --- a/bootstrap/bootstrap.php +++ b/bootstrap/bootstrap.php @@ -451,7 +451,7 @@ public static function parseMessageForFB($ret, $metaMessageData = array(), $mess if ($hash == $file->security_hash) { $elements = [ - new Tgallice\FBMessenger\Model\Button\WebUrl(erTranslationClassLhTranslation::getInstance()->getTranslation('file/file','Download'), 'https://devmysql.livehelperchat.com' . erLhcoreClassDesign::baseurl('file/downloadfile')."/{$file->id}/{$hash}" ) + new Tgallice\FBMessenger\Model\Button\WebUrl(erTranslationClassLhTranslation::getInstance()->getTranslation('file/file','Download'), 'https://' . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('file/downloadfile')."/{$file->id}/{$hash}" ) ]; $template = new Tgallice\FBMessenger\Model\Attachment\Template\Button(erTranslationClassLhTranslation::getInstance()->getTranslation('file/file','Download').' - '.htmlspecialchars($file->upload_name).' ['.$file->extension.']', $elements); @@ -573,7 +573,7 @@ public static function parseMessageForFB($ret, $metaMessageData = array(), $mess $messages = array(); - if (!isset($metaMessageData['content']['quick_replies']) && !isset($metaMessageData['content']['buttons_generic']) && !isset($metaMessageData['content']['buttons_generic'])) + if (!isset($metaMessageData['content']['quick_replies']) && !isset($metaMessageData['content']['buttons_generic']) && !isset($metaMessageData['content']['generic'])) { // Keep messages order as it was foreach ($parts as $key => $part) @@ -643,7 +643,51 @@ public static function parseMessageForFB($ret, $metaMessageData = array(), $mess } $messages[] = new Tgallice\FBMessenger\Model\Attachment\Template\Button('rest', $elements); } elseif ($type == 'generic') { - // @todo implement + + $elements = []; + foreach ($metaMessage['items'] as $item) { + $buttons = []; + foreach ($item['buttons'] as $button) { + if ($button['type'] == 'url') { + $buttons[] = new Tgallice\FBMessenger\Model\Button\WebUrl($button['content']['name'], $button['content']['payload']); + } elseif ($button['type'] == 'trigger') { + $buttons[] = new Tgallice\FBMessenger\Model\Button\Postback($button['content']['name'], 'trigger__'.$item['content']['payload']. '__' . md5($item['content']['name']) . '__' . $messageId); + } elseif ($item['type'] == 'updatechat') { + // This scenario is not supported in general + } else { + $elements[] = new Tgallice\FBMessenger\Model\Button\Postback($item['content']['name'], 'bpayload__'.$item['content']['payload']. '__' . md5($item['content']['name']) . '__' . $messageId ); + } + } + + if ($item['type'] == 'url') { + $elements[] = new Tgallice\FBMessenger\Model\Attachment\Template\Generic\Element( + $item['content']['title'], + $item['content']['subtitle'], + $item['content']['img'], + $buttons, + new Tgallice\FBMessenger\Model\DefaultAction($item['content']['payload']) + ); + } elseif ($item['type'] == 'trigger') { + $elements[] = new Tgallice\FBMessenger\Model\Attachment\Template\Generic\Element( + $item['content']['title'], + $item['content']['subtitle'], + $item['content']['img'], + $buttons + ); + } elseif ($item['type'] == 'updatechat') { + // This scenario is not supported in general + } else { + $elements[] = new Tgallice\FBMessenger\Model\Attachment\Template\Generic\Element( + $item['content']['title'], + $item['content']['subtitle'], + $item['content']['img'], + $buttons + ); + } + } + + $messages[] = new Tgallice\FBMessenger\Model\Attachment\Template\Generic($elements); + } elseif ($type == 'list') { // @todo implement } elseif ($type == 'typing') {