DEV Community

Cover image for Give Voice to Your Mule Message
Archana-Invenio
Archana-Invenio

Posted on

Give Voice to Your Mule Message

Component Diagram:

Component

Sequence Diagram:

sequence

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

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

Figure3

Step 2:

Installation:

mvn install

Figure4

Figure5

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

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

Step 4:

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

Figure8

Figure9

   <dependency>  
        <groupId>com.mule.alexa.connector</groupId>
    <artifactId>alexa-mule-connector</artifactId>
    <version>1.0.0</version>
    <classifier>mule-plugin</classifier>
    </dependency>
Enter fullscreen mode Exit fullscreen mode

Figure10

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

Figure12

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

Figure14

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

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": {}
        }
    }
Enter fullscreen mode Exit fullscreen mode

Alexa Developer Account setup:

What you will need:

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

Figure16

aws2

aws3

aws4

aws5

aws6

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

aws8

aws9

aws10

aws11

aws12

aws13

bbc1

bbc2

bbc3

bbc4

bbc5

bbc6

bbc7

bbc8

ssd1

ssd2

The sample custom function can be created from here.
Use the below command to clone the project from above link.

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

ssd3

Create the jar file for handlers.

ssd4

ssd5

ssd6

ssd7

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)

Use the following commands:

ssd8

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

ssd9

  1. 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

  1. 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 to enable and grant permissions to the skill created above.

s1

s2

s3

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

s4

s5

s6

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

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.

Top comments (6)

Collapse
 
vishalinvenio profile image
Vishal Konaparthi

Amazing..! Good Job!

Collapse
 
tiwari_archana profile image
Archana-Invenio

Thank You!!

Collapse
 
arpitsrm profile image
arpitsrm

Nicely Done!

Collapse
 
tiwari_archana profile image
Archana-Invenio

Thank you!!

Collapse
 
roystonlobo profile image
Royston Lobo

Thank you for your submission, Archana!

Collapse
 
srkomma profile image
srkomma

Seems like a cool project. I am going to give it a try.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.