コード例 #1
0
 function it_create_a_postback_event()
 {
     $raw = '
         {
           "sender":{
             "id":"USER_ID"
           },
           "recipient":{
             "id":"PAGE_ID"
           },
           "timestamp":1458692752478,
           "postback":{
             "payload":"USER_DEFINED_PAYLOAD"
           }
         }    
     ';
     $arr = json_decode($raw, true);
     $expectedEvent = new PostbackEvent('USER_ID', 'PAGE_ID', 1458692752478, Postback::create($arr['postback']));
     $event = $this::createPostbackEvent($arr);
     $event->shouldBeLike($expectedEvent);
     $event2 = $this::create($arr);
     $event2->shouldBeLike($expectedEvent);
 }
コード例 #2
0
 /**
  * @param array $payload
  *
  * @return PostbackEvent
  */
 public static function createPostbackEvent(array $payload)
 {
     $postback = Postback::create($payload['postback']);
     $senderId = $payload['sender']['id'];
     $recipientId = $payload['recipient']['id'];
     $timestamp = $payload['timestamp'];
     return new PostbackEvent($senderId, $recipientId, $timestamp, $postback);
 }