Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $input = json_decode(file_get_contents('php://input'), true);
- $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
- $message = $input['entry'][0]['messaging'][0]['message']['text'];
- $message_to_reply = '';
- if($message=="tshirt")
- {
- $jsonData = '{
- "recipient":{
- "id":"'.$sender.'"
- },
- "message":{
- "attachment":{
- "type":"template",
- "payload":{
- "template_type":"generic",
- "elements":[
- {
- "title":"Object1",
- "subtitle":"Description",
- "buttons":[
- {
- "type":"postback",
- "title":"L",
- "payload":"L_1"
- },{
- "type":"postback",
- "title":"XL",
- "payload":"XL_1"
- }
- ]
- }
- ]
- }
- }
- }
- }';
- }
- if($message=="XL_1")
- {
- $jsonData = '{
- "recipient":{
- "id":"'.$sender.'"
- },
- "message":{
- "text":"Added to basket"
- }
- }';
- }
- if($message=="L_1")
- {
- $jsonData = '{
- "recipient":{
- "id":"'.$sender.'"
- },
- "message":{
- "text":"Added to basket"
- }
- }';
- }
- $url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- if(!empty($input['entry'][0]['messaging'][0]['message'])){
- $result = curl_exec($ch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement