In the previous articles, we have different aspects of developing Alexa skills.
We learned how to pass state between intents and sessions.
Sometimes, you may run into a situation when you need to interact with external services.
It could be a service to fetch weather information, local news or, you can even set up a private service to interact with IoT devices.
Basically, anything you can interact with over HTTP.
Now, let’s learn how we can interact with external APIs from an Alexa skill.
Keeping some state within a single session of Alexa skill could play an important role of how the skill interacts with a user.
Keeping the state between sessions may bring your skill to another level.
By doing so, the skill can pick up the user from the middle of a conversation and proceed from there.
Sounds great? So let’s learn how we can achieve that.
Last time we have learned how to capture input from the user.
Using captured inputs we are able to handle communication with users from our skills.
But a skill does not always have a linear conversation.
We may want to ask a question and behave differently based on the answer we’ve got.
To do that, we need to keep some information in the “memory” of an Alexa skill.
To achieve that, Alexa Skill SDK provides us an ability to use Session Attributes.
Let’s see how we can use that.
In the previous articles we have built a Hello World Alexa skill.
As any other hello world programs, the skill does only one job.
We can only ask a single question and receive the single answer back.
Although you can build skill using that kind of interaction with a user, sooner or later you will feel the need of getting some custom data from a user.
For example, you may want to tell a number or a name of a city and behave differently based on the answer.
Let’s see how we can do that.
Today, I need to parse a string of a specific format and grab a couple of values from the string using Swift programming language.
Sounds like a trivial problem. All I need to do is to use a regular expression to find the information I need.
That post would not have written unless I had encountered a couple of difficulties.
I have to admit that I am relatively new to Swift and some parts of the language are not that obvious to me and probably for some beginners.
Yet another issue I’ve faced today is the Swift documentation.
The documentation looks incomplete.
Although, I might have a bad luck using documentation related to regular expressions.
Anyway. Let’s jump ahead and see how I’ve solved that issue.
I hope that solution can help someone as well.