Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. $input = json_decode(file_get_contents('php://input'), true);
  2. $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
  3. $message = $input['entry'][0]['messaging'][0]['message']['text'];
  4. $message_to_reply = '';
  5.  
  6. if($message=="tshirt")
  7. {
  8.  
  9. $jsonData = '{
  10. "recipient":{
  11. "id":"'.$sender.'"
  12. },
  13. "message":{
  14. "attachment":{
  15. "type":"template",
  16. "payload":{
  17. "template_type":"generic",
  18. "elements":[
  19. {
  20. "title":"Object1",
  21.  
  22. "subtitle":"Description",
  23.  
  24. "buttons":[
  25. {
  26. "type":"postback",
  27. "title":"L",
  28. "payload":"L_1"
  29. },{
  30. "type":"postback",
  31. "title":"XL",
  32. "payload":"XL_1"
  33. }
  34. ]
  35. }
  36. ]
  37. }
  38. }
  39. }
  40. }';
  41. }
  42. if($message=="XL_1")
  43. {
  44. $jsonData = '{
  45. "recipient":{
  46. "id":"'.$sender.'"
  47. },
  48. "message":{
  49. "text":"Added to basket"
  50. }
  51. }';
  52. }
  53. if($message=="L_1")
  54. {
  55. $jsonData = '{
  56. "recipient":{
  57. "id":"'.$sender.'"
  58. },
  59. "message":{
  60. "text":"Added to basket"
  61. }
  62. }';
  63. }
  64.  
  65. $url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
  66. $ch = curl_init($url);
  67.  
  68. curl_setopt($ch, CURLOPT_POST, 1);
  69. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
  70. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  71. if(!empty($input['entry'][0]['messaging'][0]['message'])){
  72. $result = curl_exec($ch);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement