Skip to content

Commit

Permalink
Update #1 - Conversation Started fix, Bot on() fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Necko1996 committed Jan 9, 2019
1 parent 3ec3928 commit b37b06f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
2 changes: 1 addition & 1 deletion src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function on($event)

$this->proceed = true;

return $this;
}

return $this;
// throw Exception;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Event/ConversationStartedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class ConversationStartedEvent extends Event implements EventInterface
{
public $event = 'conversation_started';

public $user;

public $type;
Expand All @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/Http/Controllers/ViberBotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion src/Messages/WelcomeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b37b06f

Please sign in to comment.