Quote of the Day is one of the templates you can select during service creation. It’s a simple template for daily inspirational quotes.
The upcoming sections will walk you through the template and explain how it works.
How it works
The template has two separate flows. You can simply invoke the service by name with no specific request (intent) to get a random quote from all the categories or invoke the service with a request for a quote from one of the five available categories.
”Ask service_name to inspire me”
You can view all available categories in the Variables panel on the service page. They are stored in the allCategories array.
Workflow for no – intent invocation
We start in the Session start block. After a brief welcome message in the Read Phase, we move on to the Daily quote block.
Using the array_rand function we pick the random category from the allCategories array and store it in the randomCategory variable. We get our random quote JSON using the HTTP client element and the randomCategory variable.
If the call to API was successful, the result is then outputted to the user. The template supports output to different platforms including devices with visual displays thanks to the Card element.
Lastly, the service exits the session.
Workflow for category intent invocation
”Ask service_name to give me a quote about life”
After the invocation like in the example above, we also begin in the Session start block. However, this time, we skip the Read Phase of the block and only the Process Phase executes. That’s because we triggered the DailyQuoteForCategory intent in the process flow.
You can view or change the utterances for the intent in the Intent Model panel on your service’s page. The intent utterances have the categories slot in them. The categories slot entity has only five categories listed and those are the ones that can be accessed through intent request invocation. If you decide to expand the number of categories, make sure you change the OK flow text in the Help processor as well. Help can also be accessed through intent request invocation, and currently, it explains which categories the user can ask for.
After the DailyQuoteForCategory intent was triggered, the OK flow of the processor is executed. The If element checks if the categories intent slot value corresponds to one of the available categories.
If it does, we make a call to the API with the requested category. If the requested category doesn’t exist, the service exits.
After making a successful call, the result is outputted and the service exits. If the call was unsuccessful, the service exits after a brief message.