Hi,
In an upcoming update, we’ll be adding WordPress hooks for sending and receiving messages that will allow you to write PHP functions to access the context variables in addition to other data in the HTTP response. Will this satisfy your needs?
Hi,
I believe it would! Any time frame as to when this update will be released?
It should be available by the end of this week. We’ll let you know as soon as it’s released.
Hi that’s great to know thank you!
Do you recommend any tutorials for WordPress hooks?
Hi,
The update has been released so you can get started with it now. The WordPress documentation has a detailed explanation of how hooks are used, though you can find a lot of other tutorials online.
For your case, you can use our plugin’s hook by doing the following:
1. Navigate to the wp-content/themes/yourthemename directory and open the functions.php file.
2. Add the following line anywhere in the file, but replace ‘function_name’ with a function name of your choosing:
add_action('watsonconv_message_parsed', 'function_name');
3. Create a PHP function with the same name. This function will now be called every time a user receives a message from the chatbot, and it will be given the body of the HTTP response as an argument. This argument will be in array format, so you can access the context like this:
function get_context_variables($response) {
$context = $response['context'];
}
Feel free to ask if you have any questions.
Hi, so does that mean we can only access one context variable at a time? We can pull it and store it elsewhere on the site?
The “context” field in the HTTP response is an array containing the current value of each of the context variables. For example, if you have context variables called “var1” and “var2”, you can access them using the $context variable like this:
$val1 = $context['var1'];
$val2 = $context['var2'];
You can then use PHP to store these values in your database. As you can tell, this will require some coding.
Fantastic, thank you very much!