Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_Wroblewski
Developer Advocate
Developer Advocate
With the February 2022 release of SAP Conversational AI, I wanted to write a few blog posts to take a practical look at a few of the new features, show you what actually changed, and a few pointers and code snippets.


Time Zone


What's new is the ability to get the user's time zone and have it set in the conversation. The effect?

  • You have the user's time zone, and can use it if you need to convert dates and times.

  • The bot can automatically interpret "now" and "tomorrow" and other date and time utterances based on the user's time zone.


Here's how it works.

With no Initialize skill, the {{timezone}} object is not set (null) and the conversation is not aware of the timezone, and if I utter "now" the datetime entity in the NLP for that utterance will be set to UTC+0.


If you add an initialize skill, it automatically comes with a Change Timezone action that sets the timezone to client_info.timezone (which is now automatically retrieved from the browser by the Web Client).


You can also manually change the time zone in any skill – for example, if you are yourself retrieving the timezone from a backend service. You must specify the IANA timezone name (like Europe/Berlin). A list is available on Wikipedia.

NOTE: No matter what, the Web Client retrieves the timezone from the user's browser and puts it in the client_info object, but the conversation timezone is not automatically set unless you use the Change Timezone action (in the Initialize or other skill).

 

Timezone in Web Client API


Since we're talking timezones, we might as well as mention other ways that you can already manipulate the timezone.

In the Web Client API, there is a method getClientInfo() that lets you set the client_info object. This new value can be used for setting the timezone in the Initialize skill, as described above.


I'll talk more about the Web Client APIs and Web Client bridge APIs, and what you can do with them,  in a future blog post.

 

Time Zone (and other date) Scripting Functions


These are not all new, but most were added only last month. We'll start with the timezone related helper function, which lets you format a date but also convert the date to a different timezone.
{{formatDate "2021-01-01T20:15:00+02:00" "DD-MM-YYYY - HH:mm" "America/Los_Angeles"}}


In the above example, the date given is UTC+2, and we converted it to UTC-8 (timezone of Los Angeles). If the date given to the formatDate helper does not have a timezone, then UTC+0 is assumed.

The convertDate helper lets you convert the date to an object or other representation, and let's you calculate the timespan between 2 dates and then get the text to express this, for example:
My birthday on March 4 is {{convertDate "03-04-2022" "relative" from=(formatDate "MM-DD-YYYY")}}


And finally, you can use the modifyDate helper to change a date, like adding a day and getting tomorrow's date.


Tip for Development


The Chat Preview does not retrieve the timezone, so it is not contained in the client_info object during your debugging. You can, of course, set a condition in your action group to set a timezone for when you are working with the Chat Preview, as in the following example.


 

Initializing Parameters


The Initialize skill gives you a way to set parameters at the start of a conversation, and make sure these parameters never change and are always available.

Only in the Initialize skill is there an action to Set Initial Context. This is like setting memory, but these values are stored in the initial_context object of the conversation and are not changed even when the memory is reset.


You can get the value in a script from the initial_context object.


There are other ways to initialize parameters via the Web Client APIs, and we'll review those next time, and see how those methods interact with the Initialize skills.

P.S.: Thanks to jonas.brand and the team for answering all my questions 😀

 
1 Comment