1. Home
  2. Docs
  3. Publishers
  4. Tutorial – Service templates walkthrough
  5. Daily quotes

Daily quotes

Daily Quotes 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 one of the eight available categories or invoke the service with a request for a quote from one of the categories.

”Ask service_name to give me a quote from inspire”

You can view the 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 show me a quote from art”

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.

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.

Was this article helpful to you? Yes No

How can we help?