paint-brush
Alexa, Ask My Website How Many Bad Reviews I Have Today?by@tole
262 reads

Alexa, Ask My Website How Many Bad Reviews I Have Today?

by Tihomir DmitrovićJune 23rd, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

We will create a simple Alexa skill that will be able to tell you how many bad reviews we have. We will use [Site Reviews, a free plugin available on WordPress.org, a popular plugin with 40K active installations. In order to work with Amazon Alexa, you’ll need an Amazon developer account and installed and configured [Convoworks WP] plugin. You can easily access any piece of information you want, enable it through voice, with no coding at all.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - Alexa, Ask My Website How Many Bad Reviews I Have Today?
Tihomir Dmitrović HackerNoon profile picture

When you are running a website there is plenty of information you wish to check and know often. Depending on what you actually do, it can be how many visitors are there, are there any new comments, how many new sales or signups are there …. the list is never ending.


Requiring access to particular information in a repetitive manner is the perfect use case for voice enabled user interface. Not just that you do not have to be on your PC, you do not even have to reach for the phone. Ultimate convenience, just tell what you want.

Amazon Alexa & Convoworks WP

If you would like to connect your website with Amazon Alexa through code, besides that there are several PHP libraries, you would quickly see that it is far from a trivial task. But you can also try to use Convoworks WP, visual builder for creating Alexa skills. It handles all communication between your website and Amazon servers and it comes with plenty of generic components that can serve you in accomplishing almost any task you have. Convoworks supports working with variables and functions. It has components which represent control structures (if, goto, foreach …) and it has components which are capable of interacting with the database. That means that you can easily access any piece of information you want, enable it through voice, with no coding at all.

Prerequisites

We will create a simple Alexa skill that will be able to tell you how many bad reviews we have. We will use Site Reviews, a free plugin available on WordPress.org. It is quite a popular plugin with 40K active installations and it works well with WooCommerce.


In order to work with Amazon Alexa, you’ll need an Amazon developer account and installed and configured Convoworks WP plugin. How to connect it you can easily learn at Convoworks documentation or with this YouTube video tutorial here.

Site reviews plugin

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.

Simple stupid version

We’ll start with creating the most simple variant, which will just query data with predefined filters and tell the result out.


Navigate to Convoworks WP, create a new service based on the “Blank“ template and configure it to work with Amazon Alexa. Go to the “Editor”, select the “Contexts” tab, add “WP Query Context“ and configure it like on this screenshot.


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.

Invoke skill with a specific request

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 Alexa Console 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 debug.log 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.