visit
Site reviews is storing data as a custom post type site-review
with the actual data in a post meta with key named _submitted
. While using the post data for storage enables us to use all the cool features that WP_Query
supports, the data in post meta is serialized array, meaning that we can not filter by it directly with query. We’ll have to use unserialize()
function and a couple of standard programming structures in the runtime to get useful data out of it.
Now that we defined our query, let’s loop over it and get the data out. First we will place WP Query Element, an element that has two sub flows which are executed depending if there are any results or not. If there are some results, we will initiate the counter variable to 0, loop over results, and increase our counter if the rating was 2 or lower. You can check how it looks below.
Now you can test it. You can check it on the Convoworks Test view, or if you configured Amazon Alexa, you can simply say: Alexa, open site reviews.
Now, let’s support an additional command which will modify the time period we want to check. We want to be able to say, Alexa, ask Site Reviews for bad reviews this week. For that we will create intent called PeriodIntent and we will fill it with example phrases - utterances. Note how we are marking actual time as a predefined convo-core.date entity. This entity will catch ordinary dates but also relative ones, like today, tomorrow, last week … Feel free to add more utterances which might sound more convenient to you.
Now we will add Session Start, a special role block to the workflow. This block is used when you want to catch additional commands issued with the skill invocation. There are several things we are handling here. First we will set the default value for our date filter in the pre-dispatch flow. This flow is the first thing to be executed when the skill starts, with or without additional command. When there is no additional command (Read Phase) we will just redirect the user to our Home conversation step.
When there is an additional command, we’ll try to catch it in our Process Phase. We are seeking for the PeriodIntent and when found, we use the date to adjust our filter variable. Fallback Flow is executed if there was an additional command but it could not be recognized.
As we are now defining a time filter through variables, we have to adjust our WP_Query
arguments.
Now it is all set and you can test it again. Use your echo device or and try to say: Alexa, ask Site Reviews for the last week’s bad reviews. If you are having problems, you can try to check your file or feel free to contact me directly. I’ll gladly help with it.
This is a very simple example that can give you an idea how easy it is to get information from your WordPress via Amazon Alexa. In this case information was stored as custom posts and we used the WP Query Context for it. In some other cases you can get data with WP DB Element which enables you to access any WordPress table, or you can use HTTP Query element that can get data even out of your system.