Want to integrate Amazon Connect IVR to Rasa open source

Hello @stephens ,

i saw your youtube video where you connect Amazon Connect connect flow to Rasa open source. i also want to integrate the same, i explored some offical docs & researched but not getting how to setup a lambada function for this LextoRasa

could you please help me ? how to setup rasa on amazon lambda function so i can also use this lambda function in amazon lex as a response and connect to amazon connect contact flow

  • Create your Lambda function that will be invoked by Lex to call Rasa, it must have the execution role AWSLambdaVPCAccessExecutionRole
  • Use the sample VPC CloudFormation template and go to the Create Stacks page. This is required to allow the Lambda function to make an external REST call to Rasa

Here’s the lambda function I used in the video:

import json
import datetime
import time
import os
import dateutil.parser
import logging
import requests
import paho.mqtt.publish as mqtt_publish

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)


def close(session_attributes, fulfillment_state, message):
    response = {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'Close',
            'fulfillmentState': fulfillment_state,
            'message': message
        }
    }

    return response


def elicit_intent(session_attributes, message):
    response = {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'ElicitIntent',
            'message': message
        }
    }

    return response

def send_mqtt(payload):
    if 'MQTT_HOST' in os.environ and 'MQTT_USER' in os.environ and 'MQTT_PASS' in os.environ:
        mqtt_publish.single("rasa/lex/utterance", payload, hostname=os.environ['MQTT_HOST'], port=1883, client_id="lambdaRasa", auth = {'username': os.environ['MQTT_USER'], 'password': os.environ['MQTT_PASS']})

def process_intent(intent_request):
    """
    Performs dialog management and fulfillment.
    """
    #slots = intent_request['currentIntent']['slots']
    #logger.debug(f"process_intent intent_request={intent_request}")
    session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
    #logger.debug(f"session_attributes: {session_attributes}, type: {type(session_attributes)}")
    sender_id = "lambda"
    if session_attributes and 'CustomerNumber' in session_attributes.keys():
        sender_id = session_attributes['CustomerNumber']

    logger.debug(f"Utterance: {intent_request['inputTranscript']}, Sender: {sender_id}")
    r = requests.post('https://website-demo.rasa.com/webhooks/rest/webhook', json={'sender':sender_id, 'message':intent_request['inputTranscript']})
    d = r.json()
    logger.debug(f"d: {d}, type: {type(d)}")
    if not d:
        text = "Sorry, but Sara is not responding. Try again another time."
        return close(
            session_attributes,
            'Fulfilled',
            {
                'contentType': 'PlainText',
                'content': text
            }
        )
    else:
    #if d is not None:
        text = d[0]['text']
    logger.debug(f"response: {text}")
    payload = f"{{\"sender_id\": \"{sender_id}\",\"utterance\":\"{intent_request['inputTranscript']}\",\"response\":\"{text}\"}}"
    #send_mqtt(payload)
    return elicit_intent(
        session_attributes,
        {
            'contentType': 'PlainText',
            'content': text
        }
    )


# --- Intents ---


def dispatch(intent_request):
    """
    Called when the user specifies an intent for this bot.
    """
    logger.debug(f"intent_request: {intent_request}")
    logger.debug('dispatch userId={}, intentName={}'.format(intent_request['userId'], intent_request['currentIntent']['name']))
    intent_name = intent_request['currentIntent']['name']
    return process_intent(intent_request)


# --- Main handler ---


def lambda_handler(event, context):
    """
    Route the incoming request based on intent.
    The JSON body of the request is provided in the event slot.
    """
    # By default, treat the user request as coming from the America/New_York time zone.
    os.environ['TZ'] = 'America/Los_Angeles'
    time.tzset()
    #logger.debug('event.bot.name={}'.format(event['bot']['name']))
    #logger.debug(f"event: {event}")
    logger.debug(f"event.sessionAttributes={event['sessionAttributes']}")

    return dispatch(event)

Okay, and where i have to specify the intents , utterence or solts in this lambda function ? and how i can traine my models ?

You don’t the user utterances are passed directly to your rasa bot by the lambda function. This is mentioned in the video here

Can i perform more complex Chatbot Opertion in this LexToRasa lambda function ?

Do you have an example of what you would like to do?

In our normal Rasa main directory we have so much of importants files like nlu.yml ,rules.yml ,domain.yml and actions.py so its easy to understand where to specify intents solts, forms , respons

But in LexToRasa lambda function we have only one file thats why am getting confused here.

The lambda function is used to pass the user utterance to the Rasa REST channel.

Nothing has to be changed in an existing Rasa bot repo structure.