RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.75k stars 4.62k forks source link

Channel specific response for custom connector with alexa does not work #8297

Closed floramarleen closed 1 year ago

floramarleen commented 3 years ago

Rasa version: 2.4.0

Rasa SDK version: 2.4.0

Python version: 3.8.5

Operating system: Windows

Issue: I connected my rasa open source bot to alexa by following the instruction given here: https://blog.rasa.com/connect-your-rasa-ai-assistant-to-amazon-alexa/. It works all fine except of the channel specific responses. It gives the output of the non channel specific responses and just ignores the ones I created.

Here is my alexa_connector.py:

import logging import json from sanic import Blueprint, response from sanic.request import Request from sanic.response import HTTPResponse #from typing import Text, Optional, List, Dict, Any from typing import Text, Dict, Any, Optional, Callable, Awaitable, NoReturn

import rasa.utils.endpoints 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 for Alexa. You can find more information on custom connectors in the Rasa docs: https://rasa.com/docs/rasa/user-guide/connectors/custom-connectors/ """

@classmethod #def name(cls): def name(cls) -> Text: return "alexa_assistant"

  1. Sanic blueprint for handling input. The on_new_message
  2. function pass the received message to Rasa Core
  3. after you have parsed it def blueprint(self, on_new_message):

alexa_webhook = Blueprint("alexa_webhook", name)

  1. required route: use to check if connector is live @alexa_webhook.route("/", methods=["GET"]) async def health(request): return response.json( {"status": "ok"}

)

  1. required route: defines @alexa_webhook.route("/webhook", methods=["POST"]) async def receive(request):

  2. get the json request sent by Alexa payload = request.json

  3. check to see if the user is trying to launch the skill intenttype = payload["request"]["type"]

  4. if the user is starting the skill, let them know it worked & what to do next if intenttype == "LaunchRequest": message = "Hello! Welcome to the Privacy Bot. You can start by saying 'hi'." session = "false" else:

  5. get the Alexa-detected intent intent = payload["request"]["intent"]["name"]

  6. makes sure the user isn't trying to end the skill if intent == "AMAZON.StopIntent": session = "true" message = "Talk to you later" else:

  7. get the user-provided text from the slot named "text" text = payload["request"]["intent"]["slots"]["text"]["value"]

  8. initialize output channel out = CollectingOutputChannel()

  9. send the user message to Rasa & wait for the

  10. response to be sent back await on_new_message(UserMessage(text, out))

  11. extract the text from Rasa's response responses = [m["text"] for m in out.messages] #message = responses[0] #give more than the first response message="" for res in responses: message=message+str(res)

    " \n" #message = str(responses[0])

    " "+str(responses[1]) session = "false"

  12. Send the response generated by Rasa back to Alexa to

  13. pass on to the user. For more information, refer to the

  14. Alexa Skills Kit Request and Response JSON Reference:

  15. https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-and-response-json-reference.html r = { "version": "1.0", "sessionAttributes": {"status": "test"}

, "response": { "outputSpeech":

{ "type": "PlainText", "text": message, "playBehavior": "REPLACE_ENQUEUED", }

, "reprompt":

Unknown macro:

{ "outputSpeech"}

, "shouldEndSession": session, }, }

return response.json(r)

return alexa_webhook

Content of domain file (domain.yml) (if relevant):

sara-tagger commented 3 years ago

Exalate commented:

sara-tagger commented:

Thanks for the issue, @ArjaanBuijk will get back to you about it soon!

You may find help in the docs and the forum, too
🤗
floramarleen commented 3 years ago

Exalate commented:

floramarleen commented:

Are there any news about this issue?

sync-by-unito[bot] commented 1 year ago

➤ Maxime Verger commented:

:bulb: Heads up! We're moving issues to Jira: https://rasa-open-source.atlassian.net/browse/OSS.

From now on, this Jira board is the place where you can browse (without an account) and create issues (you'll need a free Jira account for that). This GitHub issue has already been migrated to Jira and will be closed on January 9th, 2023. Do not forget to subscribe to the corresponding Jira issue!

:arrow_right: More information in the forum: https://forum.rasa.com/t/migration-of-rasa-oss-issues-to-jira/56569.