Give Voice to Your Mule Message
Tags: mulesofthackathon, mulemessage, alexa, anypointplatform
Published: 2020-11-24 13:41:35

#**Component Diagram:**
![Component](https://dev-to-uploads.s3.amazonaws.com/i/l8cf07v2zzd8otvsgzcw.png)

#**Sequence Diagram:**
![sequence](https://dev-to-uploads.s3.amazonaws.com/i/lnqopj4ilvl03a2rm4dv.png)

#**Alexa-Mule Adaptor:** 
The usecase of the custom Alexa-Mule Adaptor/connector is – 
it connects the mule components and push the payload via connector to the Alexa skill model which triggers the Proactive Event Message Alert and reached to the Alexa devices which has subscribed to this Alexa skill at the specified endpoints. The Alexa devices which has subscribed to this Alexa skill but the endpoint is different to which alert is not pushed via connector. Those devices will not receive any Alert Message.
The custom Alexa-Mule Adaptor/connector creates an Alexa module support Echo Alexa operation.  
Figure1 below represents the inside package structure of Alexa-Mule Adaptor/connector.

 ![Figure1](https://dev-to-uploads.s3.amazonaws.com/i/t0ab4zjuzkpx22076wko.png)

The code link is shared here:
Steps involved in the creation of connector are:
####Step 1:
After completing the connector code/either import from the source mentioned go to 
> Project ->right click ->properties

![Figure2](https://dev-to-uploads.s3.amazonaws.com/i/ilicx7q4wjacmxzslpmc.png)

![Figure3](https://dev-to-uploads.s3.amazonaws.com/i/fvaeqfmxrktkwy32raim.png)


####Step 2: 
Installation:

 `mvn install`

![Figure4](https://dev-to-uploads.s3.amazonaws.com/i/win8bkhwcc17jdu96b7c.png)


![Figure5](https://dev-to-uploads.s3.amazonaws.com/i/285sofx4incf5yq063ja.png)


####Step3: 
After successful build run the below command in the command prompt. This will install the dependencies in the local repository which can be found in `\.m2\repository\com\your package structure…`

>`mvn install:install-file -Dfile=path of the jar file  DgroupId=groupId value DartifactId=artifactId value  -Dversion=version value -Dpackaging=jar`

![Figure6](https://dev-to-uploads.s3.amazonaws.com/i/ryxpodcwnut1fdk0bxmr.png)

#####Example:  
> `mvn install:install-file -Dfile=E:\alexa-mule-connector-1.0.0-mule-plugin.jar -DgroupId=com.mule.alexa.connector -DartifactId=alexa-mule-connector -Dversion=1.0.0 -Dpackaging=jar`

![Figure7](https://dev-to-uploads.s3.amazonaws.com/i/57y0vsgk08yhs4sj8te6.png)


####Step 4:
Usage
Once installed in your local repository add the following dependency to the pom.xml of your mule project Figure 4

![Figure8](https://dev-to-uploads.s3.amazonaws.com/i/1dt0hebohqxu646brywn.png)


![Figure9](https://dev-to-uploads.s3.amazonaws.com/i/j1afaesegcfa5mxsg006.png)

 ```
   <dependency>	 
        <groupId>com.mule.alexa.connector</groupId>
	<artifactId>alexa-mule-connector</artifactId>
	<version>1.0.0</version>
	<classifier>mule-plugin</classifier>
    </dependency>
```

![Figure10](https://dev-to-uploads.s3.amazonaws.com/i/3rxefcddlo6hf5h138my.png)

####Step 5: 
After added the dependency you can use the client as below:

You can find the Alexa module. Drag and drop the Echo Alexa operation and the components which are needed to pass the payload to Alexa Device (Show in the component diagram)

![Figure11](https://dev-to-uploads.s3.amazonaws.com/i/0o3pk2vple8t00tis7oh.png)


![Figure12](https://dev-to-uploads.s3.amazonaws.com/i/nrwjktpzsm9qi3sacoq6.png)


Enter Client Id and Secret ID, also respective Environment and Region i.e. to which subscribed zone you want to send alert.

1. Environment: whether the target events will be sent to the live or development endpoints. Allowed values are dev and pro.  
2. Region: identifies the region of the Alexa endpoint to use to send proactive events. Allowed values are EU (Europe), NA (North America) and FE (Far East). Remember: if your users are located in NA and you are sending events trough the EU endpoint, users located in NA won't receive any notification.

![Figure13](https://dev-to-uploads.s3.amazonaws.com/i/o05ysnhmkd7sgcbdz7ye.png)


![Figure14](https://dev-to-uploads.s3.amazonaws.com/i/7gls8zc2lv0im1b9512h.png)

#Alexa-Mule Adaptor Testing: 

You can the run the code by passing the required client ID and Secret Id and other parameters mentioned.
 

Below figures show the response status of the connector whether it is able to reach the Alexa skill:

![Figure15](https://dev-to-uploads.s3.amazonaws.com/i/486287dtfynd7rrc7h20.png)

These are the values by default of an event when you create it:

```
{
        "timestamp": "",
        "referenceId": "UUID-AUTOGENERATED",
        "expiryTime": "",
        "event": {
          "name": "AMAZON.MessageAlert.Activated",
          "payload": {
            "state": {
              "status": "UNREAD",
              "freshness": "NEW"
            },
            "messageGroup": {
              "urgency": "URGENT",
              "creator": {
                "name": "Test"
              },
              "count": 1
            }
          }
        },
        "relevantAudience": {
            "type": "Multicast",
            "payload": {}
        }
    }
```

#Alexa Developer Account setup:

What you will need:

* [Amazon Developer Account](http://developer.amazon.com/alexa) (login if already registered) 
* [Amazon Web Services Account](http://aws.amazon.com/) (login if already registered)

> **Note:** both accounts should be same username and link both the accounts

* [AWS Command Line Interface (CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) (refer this link to install)
* [Alexa Skills Kit Command Line Interface (ASK CLI)](https://developer.amazon.com/docs/smapi/quick-start-alexa-skills-kit-command-line-interface.html) (refer this link to and install)
* [Node.JS version 8](https://nodejs.org/) (refer this link to install)

![Figure16](https://dev-to-uploads.s3.amazonaws.com/i/82s5h4malbigsee86qua.png)

![aws2](https://dev-to-uploads.s3.amazonaws.com/i/9pj8n91yudoxpcrqsqki.png)

![aws3](https://dev-to-uploads.s3.amazonaws.com/i/nczewd9tqlvmci9ksg87.png)

![aws4](https://dev-to-uploads.s3.amazonaws.com/i/v03lea369uypfp3wf847.png)

![aws5](https://dev-to-uploads.s3.amazonaws.com/i/kifpdct029l7cuy9vbob.png)

![aws6](https://dev-to-uploads.s3.amazonaws.com/i/9o8zrvj7cv0fwengyw7z.png)

> **Note:** By default, values are:  

1. Choose a model to add to your skill
2. Choose a method to host your skill's backend resources


![aws7](https://dev-to-uploads.s3.amazonaws.com/i/65zjd31j7ef8euan24fx.png)

![aws8](https://dev-to-uploads.s3.amazonaws.com/i/kx2tmkxg157tc5y0w10t.png)

![aws9](https://dev-to-uploads.s3.amazonaws.com/i/lty82czqqz1lk05i1jfa.png)

![aws10](https://dev-to-uploads.s3.amazonaws.com/i/lpfnbotok40vw5sav09n.png)

![aws11](https://dev-to-uploads.s3.amazonaws.com/i/rcupphbbjv0fncl26meg.png)

![aws12](https://dev-to-uploads.s3.amazonaws.com/i/t8skul84kqym9kitno4q.png)

![aws13](https://dev-to-uploads.s3.amazonaws.com/i/nw99q0pp9etlpmyu9req.png)

![bbc1](https://dev-to-uploads.s3.amazonaws.com/i/6ulxjs0kehqw55rjityj.png)

![bbc2](https://dev-to-uploads.s3.amazonaws.com/i/43ytrprpjmjgka6pw74l.png)

![bbc3](https://dev-to-uploads.s3.amazonaws.com/i/o3u7wb0l55ogb99ybukv.png)

![bbc4](https://dev-to-uploads.s3.amazonaws.com/i/vsp3aeky9z7v5d3x8me9.png)

![bbc5](https://dev-to-uploads.s3.amazonaws.com/i/h738rthsxncna5u3d3ii.png)

![bbc6](https://dev-to-uploads.s3.amazonaws.com/i/ow8kozu8bfugff1qnwc7.png)

![bbc7](https://dev-to-uploads.s3.amazonaws.com/i/0ysvn2nvfjuez546dum5.png)

![bbc8](https://dev-to-uploads.s3.amazonaws.com/i/ygvwrl9m7h0t1aep7tfb.png)

![ssd1](https://dev-to-uploads.s3.amazonaws.com/i/e8pxg9l7o2bqkoueuj5p.png)

![ssd2](https://dev-to-uploads.s3.amazonaws.com/i/2bpra9vpnq19uhafnxey.png)

The sample custom function can be created from here.
Use the below command to clone the project from above [link](https://github.com/satr/aws-lambda-on-java-with-gradle-for-simple-alexa-skill-example).

`git clone https://github.com/satr/aws-lambda-on-java-with-gradle-for-simple-alexa-skill-example`

![ssd3](https://dev-to-uploads.s3.amazonaws.com/i/l6nmy3a9fi9szp0ceegp.png)

Create the jar file for handlers.

![ssd4](https://dev-to-uploads.s3.amazonaws.com/i/iqjzp294o068o85cq2r7.png)

![ssd5](https://dev-to-uploads.s3.amazonaws.com/i/m0p2lf8k3g02xx4rd3xv.png)

![ssd6](https://dev-to-uploads.s3.amazonaws.com/i/z4hsjkcuhuqxurv5g8cj.png)

![ssd7](https://dev-to-uploads.s3.amazonaws.com/i/d4wgezm7ykarvz2s1u6s.png)

The ARN of the Lambda function should be the endpoint of Alexa Skill created in developers console the deploy the Alexa Skill.
In the command line configure ask cli using AWS lambda hosting (refer this [link](https://developer.amazon.com/en-US/docs/alexa/smapi/quick-start-alexa-skills-kit-command-line-interface.html))

Use the following commands:

![ssd8](https://dev-to-uploads.s3.amazonaws.com/i/3k1aljx2rkzpfwqwmmzk.png)

1. To get the manifest from the Alexa skill created above
`ask smapi get-skill-manifest -s {Skill-ID}`

![ssd9](https://dev-to-uploads.s3.amazonaws.com/i/x80dmhd4y6jlgdzso0jd.png)

2. To download the skill.json of your skill
`ask smapi get-skill-manifest -s {Skill-ID}> skill.json`

Open the skill.json in any editor then add permissions and events and subscriptions.

![ssd10](https://dev-to-uploads.s3.amazonaws.com/i/6iudac0lzrlcofs39bvl.png)

3.	
Use the below command to update the changes made above in skill.json
`ask smapi update-skill-manifest -g development --skill-id {Skill-ID}--manifest file:./skill.json`

#**Alexa Device Setup:**
Refer the [link](https://alexa.amazon.in/spa/index.html#cards) to enable and grant permissions to the skill created above.

![s1](https://dev-to-uploads.s3.amazonaws.com/i/db1o2chibrk3mi8q83b2.png)

![s2](https://dev-to-uploads.s3.amazonaws.com/i/xliir4lqeehltiqsoaf5.png)

![s3](https://dev-to-uploads.s3.amazonaws.com/i/jvssqhimwdwvz2nbnj43.png)

Once skill is enabled you will get the below options. Then go to setting and grant the permissions.

![s4](https://dev-to-uploads.s3.amazonaws.com/i/tfirlsdc719ncuk82eds.png)

![s5](https://dev-to-uploads.s3.amazonaws.com/i/5id124r5upnh7xvtxgdn.png)

![s6](https://dev-to-uploads.s3.amazonaws.com/i/61kh92qj2nmddi2byupo.png)

Once the skill is enabled the client Id and secret key will be generated in the developer console permission tab.
This is Id’s as a parameter in the mule connector/Adapter (explained in above screenshots)


###**Download [Alexa-Mule-Adapter/Connector](https://github.com/Archana-Invenio/Mulesoft-hakathon)**

#**Future Extension of the Adapter:**

We believe and trying for the extension of the above Alexa-Mule-Adapter/Connector which can hold the following capabilities. 
Alexa-Mule-Adapter/Connector current module named – Alexa has only one operation named Echo Alexa.

Future extension to the Module - Alexa is adding the below two operations.
1. Route your flow via voice 
2. Make decision via voice

**Route your flow via voice:**
	The functionality of this operation is that -user can manage and interact with the mule flow i.e. basically calling the operations/looking for specific operation in mule project.

**Make decision via voice:**
	The Functionality of this operation is that – user can provide the input i.e. decision YES/NO START/STOP STATUS and to the certain extent login credentials, handling some of the auto fix issues via voice based on predefined keywords on which device is trained to perform the action specified by user.