Facebook Chat Bot - How do I test the welcome mess

2019-03-20 13:25发布

问题:

My chat bot is working great but I am having trouble debugging the Welcome message functionality because it only shows up when a conversation is initiated (although i'm pretty sure it's not working having tried it on a colleagues phone). How do I reset my chat so it sees me as a new user interacting with it?

This is my welcome PHP Script at the moment

<?php

function webhook() {
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];

if ($verify_token === 'MYTOKEN') {
  echo $challenge;
}

$input = json_decode(file_get_contents('php://input'), true); 
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];

$welcomejson = welcomemessage();

welcomesend($json);

function message() {
$json = '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[
     {
      "message":{
      "text":"Welcome to My BOT!"
     }
}
]
}';
return $json;
}

function send($json) {
$url = 'https://graph.facebook.com/v2.6/MYPAGEID/thread_settings?access_token=MYTOKEN';

//Initiate cURL.
$ch = curl_init($url);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

 //Execute the request
 $result = curl_exec($ch);
}

回答1:

Try this:

  1. Open Facebook in a desktop browser and go to the page linked to your messenger bot
  2. Press "Message"
  3. Inside the message popup/discussion choose "Options" (cog icon)
  4. Select "Delete Conversation..." and say "Delete Conversation" in the confirmation prompt
  5. Select "Message" again
  6. Select "Get Started"

Step 4. really deletes the chat history you are having with the page/app so beware.



回答2:

  • On desktop, delete the conversation and message the page again.

This will allow you to see the "Get Started" button again, allowing you to test it and your welcome message's functionality.

If you're trying to test the "Messenger Greeting", it's a lot more complicated. See below.


On Desktop the "Messenger Greeting" still will not show up after deleting the conversation. Only the "get started" button reappears. I believe this is a bug that I will be opening up a ticket for most likely.

You can get a similar experience on mobile by deleting the conversation, uninstalling, and reinstalling Messenger, but once again that does not display the Messenger greeting, it only shows the get started button.

Not being able to see the Messenger Greeting again is an issue for developers who are picky about the line-by-line formatting of the Messenger greeting, or who simply need to see it again for a demo of the messenger bot once the greeting has already been seen.

Thankfully, although EXTREMELY painful, there's a workaround. Basically have to re-setup your bot.

  1. Create a new page
  2. NEVER OPEN A MESSAGE WITH THE PAGE/BOT UNTIL STEP 17
  3. Click settings, Messenger, and set your messenger greeting, and press save.
  4. Since that doesn't actually save the toggled setting for some reason, select a different thing from messenger in the sidebar
  5. Reselect Messenger
  6. Turn on the greeting (the message should have saved properly, just not the toggle for whether its on or off)
  7. Change to a different thing in sidebar
  8. Re-select Messenger and double check that the messenger greeting is enabled
  9. Create a new app
  10. Add Messenger as a product
  11. Select the page and copy the page access token
  12. Put the page access token where it is needed in your code
  13. Run your code
  14. Connect to the webhook url with your verify token and all the boxes checked
  15. After webhook connection is successful, subscribe it to your new page
  16. Run your curl command to enable the 'get started' button and your welcome message that will happen after the button is pressed
  17. Open a message with your page, and the Messenger greeting and get started button should appear. YOU GET ONE CHANCE AND THEN YOU'LL HAVE TO REPEAT ALL OF THESE STEPS TO SEE THE GREETING AGAIN.

I believe the toggle on messenger greeting not saving right is also a bug, and I may open a ticket for it.



回答3:

There is a way to get the welcome screen in Messenger on iOS (at least as of Apr 28th), although it's super annoying. Basically, in addition to deleting the convo, you have to reinstall the app on your phone.

  1. Go to the paged linked to your bot in facebook on desktop
  2. Archive the conversation
  3. Open Messenger on your phone and delete the conversion by swiping right on the cell in the conversation list
  4. Delete Messenger from your phone
  5. Reinstall Messenger from the App Store