Currently working on an Alexa skill and I’m keen to utilize Rasa to improve responses. I’m having a bit of trouble integrating Rasa with Alexa. Does anyone know how to integrate it?
Hi here, is there any tutorial to connect alexa with RASA?
Hi shruthi, Can you please explain how you integrated alexa and RASA.
Hi Shruthi, I just want to know how you are getting the user utterance from alexa, in this reply you have told when you say something alexa passes it as it is to your rasa bot, I am struck here, in google assistant i am getting whole user utterance but i am not getting in alexa, it will be really helpful if you share how you did.
Thank you.
Hey Akela! Was this tutorial about creating a custom connector to Amazon’s Alexa that you mention in your August 2018 reply to a user named davemac (linked below) ever released?
I would love to know, thanks so much! Please have a good day.
Hi @mepc36 for Alexa we never did a tutorial, as it’s not very developer friendly. However, we did do a blog post on a Google Assitant connector here
Great, thanks so much @akelad! Really appreciate it
I’ve done a poc to connect Alexa with Rasa Core. The NLU part is however performed by Alexa. You may have a look at this:
Wow, that seems perfect Heiko! I’m going to start implementing this in a little while, and I’ll let you know how it goes! Thanks again @HeiooDo
Cool stuff!
Is there any updates how to connect rasa with the Alexa?
Hi @yashwanths112 did you manage to run the rasa on alexa?
yes, I am able to run Rasa on Alexa, The main problem i had was not getting complete user utterance from alexa, so I used this(mentioned below) alexa skill json and got complete user utterance and fed it to RASA NLU.
{
"interactionModel": {
"languageModel": {
"invocationName": "siri",
"intents": [
{
"name": "SaveIntent",
"slots": [
{
"name": "text",
"type": "catchAll"
}
],
"samples": [
"{text}"
]
}
],
"types": [
{
"name": "catchAll",
"values": [
{
"name": {
"value": "allonymous isoelectrically salubrity apositia phantomize Sangraal externomedian phylloidal"
}
},
{
"name": {
"value": "imbreviate Bertie arithmetical undramatically braccianite eightling imagerially leadoff"
}
},
{
"name": {
"value": "mistakenness preinspire tourbillion caraguata chloremia unsupportedness squatarole licitation"
}
},
{
"name": {
"value": "Cimbric sigillarid deconsecrate acceptableness balsamine anostosis disjunctively chafflike"
}
},
{
"name": {
"value": "earsplitting mesoblastema outglow predeclare theriomorphism prereligious unarousing"
}
},
{
"name": {
"value": "ravinement pentameter proboscidate unexigent ringbone unnormal Entomophila perfectibilism"
}
},
{
"name": {
"value": "defyingly amoralist toadship psoatic boyology unpartizan merlin nonskid"
}
},
{
"name": {
"value": "broadax lifeboat progenitive betel ashkoko cleronomy unpresaging pneumonectomy"
}
},
{
"name": {
"value": "overharshness filtrability visual predonate colisepsis unoccurring turbanlike flyboy"
}
},
{
"name": {
"value": "kilp Callicarpa unforsaken undergarment maxim cosenator archmugwump fitted"
}
},
{
"name": {
"value": "ungutted pontificially Oudenodon fossiled chess Unitarian bicone justice"
}
},
{
"name": {
"value": "compartmentalize prenotice achromat suitability molt stethograph Ricciaceae ultrafidianism"
}
},
{
"name": {
"value": "slotter archae contrastimulant sopper Serranus remarry pterygial atactic"
}
},
{
"name": {
"value": "superstrata shucking Umbrian hepatophlebotomy undreaded introspect doxographer tractility"
}
},
{
"name": {
"value": "obstructionist undethroned unlockable Lincolniana haggaday vindicatively tithebook"
}
},
{
"name": {
"value": "unsole relatively Atrebates Paramecium vestryish stockfish subpreceptor"
}
},
{
"name": {
"value": "babied vagueness elabrate graphophonic kalidium oligocholia floccus strang"
}
},
{
"name": {
"value": "undersight monotriglyphic uneffete trachycarpous albeit pardonableness Wade"
}
},
{
"name": {
"value": "minacious peroratory filibeg Kabirpanthi cyphella cattalo chaffy savanilla"
}
},
{
"name": {
"value": "Polyborinae Shakerlike checkerwork pentadecylic shopgirl herbary disanagrammatize shoad"
}
}
]
}
]
}
}
}
Thanks for your response @yashwanths112 I will try to use this json, can you please help me with the integration?
Thanks Shubham
Hi @svshubham01, To integrate with alexa you need to put that JSON in alexa skill kit json editor, now you will get full user utterance as a slot, then download alexa skill kit sdk for python(or whatever language you are using), through sdk you will get the json from alexa where you will get user utterance as a slot value, now feed that user utterance to the RASA and get the result and push it back to the alexa. (I did this long back, I couldn’t find the code may be it is in my other laptop once I find that I will post it, but this is not a proper connector to alexa like @Juste did for google assistant but it works).
Thanks @yashwanths112 for the advise. I will try to do it… and I hope @Juste will provide us a connector for alexa like she provided for google assistant.
Hi here is the solution, I am able to Integrate the Rasa With Alexa First put this Json into your Alexa Skill to get the user Utterence
{
"interactionModel": {
"languageModel": {
"invocationName": "test rasa",
"intents": [
{
"name": "SaveIntent",
"slots": [
{
"name": "text",
"type": "catchAll"
}
],
"samples": [
"{text}"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop",
"ok bye"
]
}
],
"types": [
{
"name": "catchAll",
"values": [
{
"name": {
"value": "allonymous isoelectrically salubrity apositia phantomize Sangraal externomedian phylloidal"
}
},
{
"name": {
"value": "imbreviate Bertie arithmetical undramatically braccianite eightling imagerially leadoff"
}
},
{
"name": {
"value": "mistakenness preinspire tourbillion caraguata chloremia unsupportedness squatarole licitation"
}
},
{
"name": {
"value": "Cimbric sigillarid deconsecrate acceptableness balsamine anostosis disjunctively chafflike"
}
},
{
"name": {
"value": "earsplitting mesoblastema outglow predeclare theriomorphism prereligious unarousing"
}
},
{
"name": {
"value": "ravinement pentameter proboscidate unexigent ringbone unnormal Entomophila perfectibilism"
}
},
{
"name": {
"value": "defyingly amoralist toadship psoatic boyology unpartizan merlin nonskid"
}
},
{
"name": {
"value": "broadax lifeboat progenitive betel ashkoko cleronomy unpresaging pneumonectomy"
}
},
{
"name": {
"value": "overharshness filtrability visual predonate colisepsis unoccurring turbanlike flyboy"
}
},
{
"name": {
"value": "kilp Callicarpa unforsaken undergarment maxim cosenator archmugwump fitted"
}
},
{
"name": {
"value": "ungutted pontificially Oudenodon fossiled chess Unitarian bicone justice"
}
},
{
"name": {
"value": "compartmentalize prenotice achromat suitability molt stethograph Ricciaceae ultrafidianism"
}
},
{
"name": {
"value": "slotter archae contrastimulant sopper Serranus remarry pterygial atactic"
}
},
{
"name": {
"value": "superstrata shucking Umbrian hepatophlebotomy undreaded introspect doxographer tractility"
}
},
{
"name": {
"value": "obstructionist undethroned unlockable Lincolniana haggaday vindicatively tithebook"
}
},
{
"name": {
"value": "unsole relatively Atrebates Paramecium vestryish stockfish subpreceptor"
}
},
{
"name": {
"value": "babied vagueness elabrate graphophonic kalidium oligocholia floccus strang"
}
},
{
"name": {
"value": "undersight monotriglyphic uneffete trachycarpous albeit pardonableness Wade"
}
},
{
"name": {
"value": "minacious peroratory filibeg Kabirpanthi cyphella cattalo chaffy savanilla"
}
},
{
"name": {
"value": "Polyborinae Shakerlike checkerwork pentadecylic shopgirl herbary disanagrammatize shoad"
}
}
]
}
]
}
}}
After that create a file named alexa_connector.py and paste this following code and don’t forget to add alexa_connector.AlexaConnector: in your credentials.yml file:
import logging
import json
from sanic import Blueprint, response
from sanic.request import Request
from typing import Text, Optional, List, Dict, Any
from rasa.core.channels.channel import UserMessage, OutputChannel
from rasa.core.channels.channel import InputChannel
from rasa.core.channels.channel import CollectingOutputChannel
logger = logging.getLogger(__name__)
class AlexaConnector(InputChannel):
"""A custom http input channel.
This implementation is the basis for a custom implementation of a chat
frontend. You can customize this to send messages to Rasa Core and
retrieve responses from the agent."""
@classmethod
def name(cls):
return "ama_alexa"
def blueprint(self, on_new_message):
alexa_webhook = Blueprint('alexa_webhook', __name__)
@alexa_webhook.route("/", methods=['GET'])
async def health(request):
return response.json({"status": "ok"})
@alexa_webhook.route("/webhook", methods=['POST'])
async def receive(request):
payload = request.json
intenttype = payload['request']['type']
if intenttype == 'LaunchRequest':
message = "Hello! Welcome to the Rasa-powered Alexa skill. You can start by saying hi."
session = 'false'
elif intenttype == 'SessionEndedRequest':
message = "Talk to you later."
session = 'true'
else:
intent = payload['request']['intent']['name']
print(intent)
if intent == 'AMAZON.StopIntent':
session = 'true'
message = 'Talk to you later'
else:
text = payload['request']['intent']['slots']['text']['value']
#print(text)
out = CollectingOutputChannel()
await on_new_message(UserMessage(text, out))
responses = [m["text"] for m in out.messages]
message = responses[0]
session = 'false'
r = {
"version": "0.1",
"sessionAttributes": {
"status": "test"
},
"response": {
"outputSpeech": {
"type": "PlainText",
"text": message,
"playBehavior": "REPLACE_ENQUEUED"
},
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": message,
"playBehavior": "REPLACE_ENQUEUED"
}
},
"shouldEndSession": session
}
}
return response.json(r)
return alexa_webhook
One thing to keep in mind during this testing for the voice platforms, you will also need to setup a check for when the skill should stop listening and send back the requested response payload that google and alexa need. So that the skill stops listening, otherwise you will not make it past getting the skill getting published either.
For google for example Conversation exits | Conversational Actions | Google Developers
For Alexa it is shouldEndSession
which is outlined more at Handle Requests Sent by Alexa | Alexa Skills Kit
Just something I ran into and to be mindful of.
The tutorial is (finally) live! You can find it here: Connect Your Rasa AI Assistant to Amazon Alexa
And a big thank you to @svshubham01 & @HeiooDo.