2016-07-11 10 views

答えて

3

あなたは何を意味するか、このですか?

https://github.com/pimax/fb-messenger-php-example/blob/master/index.php

$data = json_decode(file_get_contents("php://input"), true, 512, JSON_BIGINT_AS_STRING); 

if (!empty($data['entry'][0]['messaging'])) { 

     foreach ($data['entry'][0]['messaging'] as $message) { 

     $command = ""; 

     // When bot receive message from user 
     if (!empty($message['message'])) { 
      $command = $message['message']['text'];   
     } 
     // When bot receive button click from user 
     else if (!empty($message['postback'])) { 
      $command = $message['postback']['payload']; 
     } 
    } 
} 



// Handle command 
switch ($command) { 
    // When bot receive "text" 
    case 'text': 
     $bot->send(new Message($message['sender']['id'], 'This is a simple text message.')); 
     break; 
    // When bot receive "image" 
    case 'image': 
     $bot->send(new ImageMessage($message['sender']['id'], 'https://developers.facebook.com/images/devsite/fb4d_logo-2x.png')); 
     break; 
    // When bot receive "image" 
    case 'local image': 
     $bot->send(new ImageMessage($message['sender']['id'], dirname(__FILE__).'/fb4d_logo-2x.png')); 
     break; 
    // When bot receive "profile" 
    case 'profile': 
     $user = $bot->userProfile($message['sender']['id']); 
     $bot->send(new StructuredMessage($message['sender']['id'], 
      StructuredMessage::TYPE_GENERIC, 
      [ 
       'elements' => [ 
        new MessageElement($user->getFirstName()." ".$user->getLastName(), " ", $user->getPicture()) 
       ] 
      ] 
     )); 
     break; 
    // When bot receive "button" 
    case 'button': 
     $bot->send(new StructuredMessage($message['sender']['id'], 
      StructuredMessage::TYPE_BUTTON, 
      [ 
       'text' => 'Choose category', 
       'buttons' => [ 
        new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'), 
        new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button'), 
        new MessageButton(MessageButton::TYPE_POSTBACK, 'Third button') 
       ] 
      ] 
    )); 
    break; 
    // When bot receive "generic" 
    case 'generic': 
     $bot->send(new StructuredMessage($message['sender']['id'], 
      StructuredMessage::TYPE_GENERIC, 
      [ 
       'elements' => [ 
        new MessageElement("First item", "Item description", "", [ 
         new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'), 
         new MessageButton(MessageButton::TYPE_WEB, 'Web link', 'http://facebook.com') 
        ]), 
        new MessageElement("Second item", "Item description", "", [ 
         new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'), 
         new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button') 
        ]), 
        new MessageElement("Third item", "Item description", "", [ 
         new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'), 
         new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button') 
        ]) 
       ] 
      ] 
     )); 

    break; 
    // When bot receive "receipt" 
    case 'receipt': 
     $bot->send(new StructuredMessage($message['sender']['id'], 
      StructuredMessage::TYPE_RECEIPT, 
      [ 
       'recipient_name' => 'Fox Brown', 
       'order_number' => rand(10000, 99999), 
       'currency' => 'USD', 
       'payment_method' => 'VISA', 
       'order_url' => 'http://facebook.com', 
       'timestamp' => time(), 
       'elements' => [ 
        new MessageReceiptElement("First item", "Item description", "", 1, 300, "USD"), 
        new MessageReceiptElement("Second item", "Item description", "", 2, 200, "USD"), 
        new MessageReceiptElement("Third item", "Item description", "", 3, 1800, "USD"), 
       ], 
       'address' => new Address([ 
        'country' => 'US', 
        'state' => 'CA', 
        'postal_code' => 94025, 
        'city' => 'Menlo Park', 
        'street_1' => '1 Hacker Way', 
        'street_2' => '' 
       ]), 
       'summary' => new Summary([ 
        'subtotal' => 2300, 
        'shipping_cost' => 150, 
        'total_tax' => 50, 
        'total_cost' => 2500, 
       ]), 
       'adjustments' => [ 
        new Adjustment([ 
         'name' => 'New Customer Discount', 
         'amount' => 20 
        ]), 
        new Adjustment([ 
         'name' => '$10 Off Coupon', 
         'amount' => 10 
        ]) 
       ] 
      ] 
     )); 
    break; 
    case 'set menu': 
     $bot->setPersistentMenu([ 
      new MessageButton(MessageButton::TYPE_WEB, "First link", "http://yandex.ru"), 
      new MessageButton(MessageButton::TYPE_WEB, "Second link", "http://google.ru") 
     ]); 
    break; 
    case 'delete menu': 
     $bot->deletePersistentMenu(); 
    break; 
    // Other message received 
    default: 
     $bot->send(new Message($message['sender']['id'], 'Sorry. I don’t understand you.')); 
} 
1

PHPを使用すると、あなたのFBロボットが人間であると思われる要求を送信することになります。

通常、これはこれらのクエリを生成するjavascriptです。あなたは同じものを送る必要があります。

これは、CURLライブラリとchrome devtools &ネットワークタブを使用して行うことができます。

http://php.net/manual/en/book.curl.php

関連する問題