# Want to integrate Amazon Connect IVR to Rasa open source

**URL:** <https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962>\
**Category:** Rasa Open Source\
**Created:** [August 17, 2021, 11:27am UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962 "2021-08-17T11:27:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![manishsonawane1998](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/manishsonawane1998/32/16583_2.png) [@manishsonawane1998](https://forum.rasa.com/u/manishsonawane1998)\
**Post date:** [August 17, 2021, 11:28am UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/1 "2021-08-17T11:28:00Z")

</div>

Hello @stephens ,

i saw your [youtube](https://youtu.be/ws6zhQzoPdQ) 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

---

<div class="post-metadata">

**Author:** ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)\
**Post date:** [August 17, 2021, 5:21pm UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/2 "2021-08-17T17:21:59Z")

</div>

- 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](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/templates/vpc-privatepublic.yaml) and go to the [Create Stacks page](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks?filteringText=&filteringStatus=active&viewNested=true&hideStacks=false). **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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![manishsonawane1998](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/manishsonawane1998/32/16583_2.png) [@manishsonawane1998](https://forum.rasa.com/u/manishsonawane1998)\
**Post date:** [August 20, 2021, 6:27am UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/3 "2021-08-20T06:27:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)\
**Post date:** [August 20, 2021, 2:53pm UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/4 "2021-08-20T14:53:41Z")

</div>

You don’t the user utterances are passed directly to your rasa bot by the lambda function. This is mentioned in the video [here](https://youtu.be/ws6zhQzoPdQ?t=48)

---

<div class="post-metadata">

**Author:** ![manishsonawane1998](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/manishsonawane1998/32/16583_2.png) [@manishsonawane1998](https://forum.rasa.com/u/manishsonawane1998)\
**Post date:** [August 24, 2021, 5:04am UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/5 "2021-08-24T05:04:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)\
**Post date:** [August 24, 2021, 5:09pm UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/6 "2021-08-24T17:09:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![manishsonawane1998](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/manishsonawane1998/32/16583_2.png) [@manishsonawane1998](https://forum.rasa.com/u/manishsonawane1998)\
**Post date:** [August 25, 2021, 6:26am UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/7 "2021-08-25T06:26:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)\
**Post date:** [August 27, 2021, 9:41pm UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/8 "2021-08-27T21:41:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BernaRampl](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@BernaRampl](https://forum.rasa.com/u/BernaRampl)\
**Post date:** [February 18, 2022, 3:23pm UTC](https://forum.rasa.com/t/want-to-integrate-amazon-connect-ivr-to-rasa-open-source/46962/9 "2022-02-18T15:23:34Z")

</div>

Wow, thank you so much for this valuable information. I don’t know much about software myself, but my brother is a programmer, and I think he will be interested in this. Just to let you know how dumb I am about technology, I can’t connect these scales [Amazon.com](https://www.amazon.com/Vont-Smart-Body-Scale-Black/dp/B08XYX8RDR/) to my phone. Although I understood from the instructions, it is possible to do it. My brother is on vacation now, so I have no one to ask. If anyone understands how this works, contact me, and let’s talk about it.
