Skip to content

Commit

Permalink
feat(line): add message_type into message hookevent
Browse files Browse the repository at this point in the history
  • Loading branch information
GimmyHchs committed Jun 13, 2018
1 parent 84ec50d commit 23bec64
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Eloquents/Line/MessageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MessageEvent extends Eloquent implements IWebhookEvent

protected $fillable = [
'type',
'message_type',
'reply_token',
'timestamp',
'source_type',
Expand Down
1 change: 1 addition & 0 deletions app/Services/Line/WebhookParsers/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function parse(array $event, bool $is_auto_save = false): IWebhookEvent
$source_id = array_get($event, "source.{$source_type}Id");
$message_event = new MessageEvent([
'type' => array_get($event, 'type'),
'message_type' => array_get($event, 'message.type'),
'reply_token' => array_get($event, 'replyToken'),
'timestamp' => intval(array_get($event, 'timestamp') / 1000),
'source_type' => $source_type,
Expand Down
1 change: 1 addition & 0 deletions database/factories/LineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
$factory->define(MessageEvent::class, function (Faker $faker) {
return [
'type' => 'message',
'message_type' => $faker->word,
'reply_token' => str_random(20),
'timestamp' => Carbon::now(),
'source_type' => $faker->word,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function up()
Schema::create('line_message_events', function (Blueprint $table) {
$table->increments('id');
$table->string('type', 15);
$table->string('message_type', 15);
$table->string('reply_token', 50);
$table->timestamp('timestamp');
$table->string('source_type', 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testParse()
$this->assertInstanceOf(stdClass::class, $event->origin_data);
$this->assertEquals('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA', $event->reply_token);
$this->assertEquals('message', $event->type);
$this->assertEquals('text', $event->message_type);
$this->assertEquals($expect_carbon->toDateTimeString(), $event->timestamp->toDateTimeString());
$this->assertEquals('user', $event->source_type);
$this->assertEquals('C8900d40ace9ee5d64f93120330ad8872', $event->source_id);
Expand Down

0 comments on commit 23bec64

Please sign in to comment.