DEV Community

Cover image for Cloud Hub Alexa Skill Set -Command your IAAS to work for you
Razia-Invenio Business Solutions
Razia-Invenio Business Solutions

Posted on

Cloud Hub Alexa Skill Set -Command your IAAS to work for you

Component Diagram

Alt Text

Sequence Diagram

Alt Text

Pre-requisite:

Alexa SDK

The usecase of Alexa CloudHub Commander:

We have developed an Alexa skill which will make the life easier for the user just by listening to the command. Since it is a personalized skill it can hold the credentials and also maintains the session. The intuitive idea behind this is to command the IAAS for you. The user can ask for any information*(Ex: Server, API, application status, deployment status)* if authenticated otherwise need to authenticate first by providing their credentials. Basically the skill is calling the CloudHub APIs internally and based on that provide the response. Apart from this some of the automation work can also be implemented in future such as deployment of the chatbot application in tomcat which is built on Spring Boot. (explained in the future extension section).

Steps for Alexa Skill creation:

To create the Alexa skill there are several methods but in this case we are using voiceflow platform to create the skill and then uploading it to Alexa Developer Console. The reason behind using this platform to maintain the flow and also creating the SSML pattern in easiest way.

The steps to do this is as follows:

1.Login to your voiceflow account

Alt Text

2.Create a new project.

Alt Text

3.Select the channel.

Alt Text

4.Give the invocation name and you are ready to create your skill.

Alt Text

5.Create the flow of the skill using the available steps.

Alt Text

6.A snapshot of CloudHub Alexa Skill Set flow.

Alt Text

Alt Text

Alt Text

7.Once the design is ready test it with using prototype tab.
Alt Text

8.For the first session it will ask your credentials and then store it for another sessions. It also stores the bearer token for the session to call the CloudHub APIs.

Alt Text

9.Now you are ready to upload this skill on Alexa.

Alt Text

10.Finally test is using the Alexa device or from the developer console.

Alt Text

Note Sometimes it might not work properly from the console as it doesn't take the special character or capital letter used in the credentials. Will try to fix it soon.

Endpoint:

For this we have used the HTTPs endpoint which is calling the CloudHub Apis.
Alt Text

Download the source code:

Working of the program:

Steps are as follows:
1.For the first session, it asks users to link to the CloudHub account. Account linking can be invoked anytime by saying "Alexa! Link my CloudHub Account". The Alexa asks for user's credentials(User name and Password) and store it in session attributes. Next time if the users ask any query related to CloudHub, using these attributes Alexa directly response to those query. Once the user provides the credentials, the Alexa used these as utterances and then authenticate the user. After successful authentication user can asks any query related to CloudHub.

Alt Text

The post method is used to invoke the first API.

https://anypoint.mulesoft.com/accounts/login?username={ch_user_name}&password={ch_password}

After successful authentication, it will generate a bearer_token which will be used as a parameter for invoking other APIs.
Copy the path of the response_token.
Alt Text

Store this token as a variable and use it as an authorization token in the proceeding APIs.
Alt Text

2.Now call the account API to get the Organization Id linked to your CloudHub.

Alt Text

GET method is used to invoke this API.

https://anypoint.mulesoft.com/accounts/api/me
Also use the same bearer_token as a Header parameter.

Alt Text

Store this Organization_Id as a another path variable and use this as a header parameter for proceeding APIs.

Alt Text

  1. Now call the environment API to get the Environment Id.

GET method is used to invoke this API.

https://anypoint.mulesoft.com/accounts/api/organizations/{org_id}/environments

Alt Text

It will generate an enviornment_id.

Alt Text

Store this environment_id as another path variable to use it in the APIs which requires env_id as a header parameter.

Alt Text

4.Now finally to get into the Run Time manager of the anypoint platform and to know about the deployed applications in your CloudHub we use the applications API.

GET method is used to invoke this API.

https://anypoint.mulesoft.com/cloudhub/api/v2/applications

Alt Text

Alt Text

Now your Alexa is ready to response for any query related to CloudHUb. From here we can either invoke CloudHub APIs or ARM REST Services.

  • Error Handling: The nature of robustness is also taken in consideration with error handling. If user tries to invoke any API which is not linked with the CloudHub Account, the Alexa tries to search the response from other APIs. For eg: User can get the server details from the Server as well as the Server Groups API. If the authorization fails Alexa sends a respond by saying "Something went wrong! Please try again". And the Alexa again generates the bearer_token to get the response from API.

AnyPoint Studio platform:

We have tested our skill for several CloudHub APIs..Some of them are mentioned below:
1.Login
2.Accounts
3.Organizations
4.Applications
5.Servers

CloudHub APIs Reference:
https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/cloudhub-api/minor/1.0/console/summary/

  • Snapshot of applications already deployed in our anypoint platform

Alt Text

Testing of ARM REST SERVICES.

Now lets test our skill with Server API.

GET method is used to invoke this API.

https://anypoint.mulesoft.com/hybrid/api/v1/servers

This header contains all the three parameters (environment_id, organization_id and bearer_token).

Alt Text

Now click on the "Test Request" tab.

Alt Text

Provide the values of all the parameters which you got earlier and then "Send Request".

Alt Text

Hurrah! The API is working. Now you are ready to run your CloudHub Alexa Skill Set.

Running the CloudHub Alexa Skill Set:

  • Once you clone this skill from Github deploy it in the Alexa Developer Console and then change the endpoint as HTTPS.
  • Invoke your skill using the invocation name(Alexa open first project).
  • In the permission tab gives the "customer name" permission for personalization of the skill.

Alt Text

  • Save and build your model to reflect the changes.

Alt Text

After successful building you are ready to test this skill either from the console or from your Alexa device.

  • Snapshot of testing the CloudHub Alexa Skill Set:

Alt Text

Future Extension of the CloudHub Alexa Skill Set:

In future we can link the AIML based chatbot which internally calls the CloudHub APIs and using the NGROK we can call our services. It will integrate the Alexa SDK with the chatbot and gives user seamless effect of interaction. To know more about it please read this post.

Top comments (1)

Collapse
 
mrram profile image
mrram

Good. Looks promising