diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/src/Bot.php b/src/Bot.php index 241f36a..f176354 100644 --- a/src/Bot.php +++ b/src/Bot.php @@ -37,9 +37,9 @@ public function on($event) $this->proceed = true; - return $this; } + return $this; // throw Exception; } diff --git a/src/Event/ConversationStartedEvent.php b/src/Event/ConversationStartedEvent.php index d4e26e1..7d4dcd7 100644 --- a/src/Event/ConversationStartedEvent.php +++ b/src/Event/ConversationStartedEvent.php @@ -13,6 +13,8 @@ class ConversationStartedEvent extends Event implements EventInterface { + public $event = 'conversation_started'; + public $user; public $type; @@ -21,9 +23,9 @@ class ConversationStartedEvent extends Event implements EventInterface public $subscribed; - public function __construct($event, $timestamp, $message_token, ViberUser $user, $type, $context, $subscribed) + public function __construct($timestamp, $message_token, ViberUser $user, $type, $context, $subscribed) { - parent::__construct($event, $timestamp, $message_token); + parent::__construct($timestamp, $message_token); $this->user = $user; $this->type = $type; diff --git a/src/Http/Controllers/ViberBotController.php b/src/Http/Controllers/ViberBotController.php index d906dba..ebfa5e5 100644 --- a/src/Http/Controllers/ViberBotController.php +++ b/src/Http/Controllers/ViberBotController.php @@ -6,6 +6,8 @@ use Paragraf\ViberBot\Bot; use Illuminate\Http\Request; use Paragraf\ViberBot\Client; +use Paragraf\ViberBot\Event\ConversationStartedEvent; +use Paragraf\ViberBot\Messages\WelcomeMessage; use Paragraf\ViberBot\TextMessage; use Paragraf\ViberBot\Model\Button; use App\Http\Controllers\Controller; @@ -18,7 +20,14 @@ class ViberBotController extends Controller { public function index(Request $request) { - (new Client())->broadcast('Zdravo tamo preko bare!', User::all(), 'name'); + + (new Bot($request, new TextMessage())) + ->on(new ConversationStartedEvent($request->timestamp, $request->message_token, + new ViberUser($request->user['id'], $request->user['name']), $request->type, $request->context, $request->subscribed )) + ->replay("Izlistavamo obaveze!") + ->send(); + +// (new Client())->broadcast('Zdravo tamo preko bare!', User::all(), 'name'); (new Bot($request, new TextMessage())) ->on(new MessageEvent($request->timestamp, $request->message_token, new ViberUser($request->sender['id'], $request->sender['name']), $request->message)) diff --git a/src/Messages/WelcomeMessage.php b/src/Messages/WelcomeMessage.php index 4b86f26..a000dbb 100644 --- a/src/Messages/WelcomeMessage.php +++ b/src/Messages/WelcomeMessage.php @@ -18,9 +18,13 @@ class WelcomeMessage extends Message implements MessageInterface public function body() { - return array_merge(parent::body(), [ + $array = array_merge(parent::body(), [ 'text' => $this->text, ]); + + unset($array['receiver']); + + return $array; } public function getText()