Hello Everyone, I want to add a live chat feature in my rasa bot and for that, I am using rocket chat I have registered the visitor and created a room in rocket chat by adding custom actions in the actions.py file, and I am able to send visitor messages in rocket chat by using custom component approach but how do send back the live agent’s response or reply back to rasa, I am not able to understand what should be the approach for it. If anyone has any solution so please let me know I have been stuck on it for the last 2 weeks.
Here is my actions.py file for the handover process:
class RegisterVisitor(Action):
def name(self) -> Text:
return "action_register_visitor"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Your code goes here
url = "http://localhost:3000/api/v1/livechat/visitor"
payload = json.dumps({
"visitor": {
"name": "Livechat Visitor",
"email": "visitor@rocket.chat",
"department": "OPB",
"token": "iNKE8a6k6cjbqWhWd",
"phone": "55 51 5555-5555",
"customFields": [
{
"key": "address",
"value": "Rocket.Chat street",
"overwrite": True
}
]
}
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
dispatcher.utter_message(text="Visitor is registered")
print(response.text)
return []
class CreateRoom(Action):
def name(self) -> Text:
return "action_create_room"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
url = "http://localhost:3000/api/v1/livechat/room?token=iNKE8a6k6cjbqWhWd"
payload={}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
return []
class ActionSendMessageToRocketChat(Action):
def name(self) -> Text:
return "action_send_msg"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
url = "http://localhost:3000/api/v1/livechat/message "
usr_msg=open('rocketchat_msg.txt',"r+")
live_msg = usr_msg.read()
payload = json.dumps({
"token": "iNKE8a6k6cjbqWhWd",
"rid": "SpN4mPdL4ehRdzawd",
"msg": live_msg
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Thank you