Issue : I am trying to achieve user to a human agent but it is not pausing the conversation. for pausing the conversation I am using ConversationPaused() .
I hope I am importing correct packages.
Content of domain file (action.py) :
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from rasa_core.trackers import DialogueStateTracker
from rasa_core.domain import Domain
from rasa_core.events import (
SlotSet,
AllSlotsReset,
ConversationPaused,
ConversationResumed,
)
import logging
import requests
import json
from rasa_sdk import Action
class Action_Humanagent(Action):
def name(self):
return "action_humanagent"
def run(self, dispatcher, tracker, domain):
response = ("Reaching out to a human agent")
dispatcher.utter_message(response)
message = ""
while message != "/unpause":
url = "http://127.0.0.1:5000/handoff/{}".format(tracker.sender_id) `//API server is written in **api.py** file, please find it below.`
req = requests.get(url)
resp = json.loads(req.text)
if "error" in resp:
raise Exception("Error fetching message: " + repr(resp["error"]))
message = resp["message"]
print("message",message)
if message != "/unpause":
dispatcher.utter_message("Human agent: {}".format(message))
return [ConversationPaused() ]
Hello, @akelad as you said I tried return [coonversationPaused()] but it is giving me error. Your actionâs âaction_humanagentâ run method returned an invalid event. Event will be ignored. Event: âConversationPaused()'
import time
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route("/")
def hello():
return "hello, bots"
meetup_store = {"toronto": {"tech": [251176370]}}
# @app.route("/handoff/<sender_id>", methods=["GET", "POST"])
@app.route("/handoff", methods=["GET", "POST"])
# def handoff(sender_id):
def handoff():
if request.method == "POST":
"""
POST
add sender id to sender store
"""
if sender_id in sender_store:
sender_store[sender_id]["replies"].append(request.get_json()["message"])
return jsonify(sender_store[sender_id])
else:
return jsonify({"error": "sender_id not found"})
else:
"""
GET
retry 10 times with 10 sec sleeps to fetch info
"""
if sender_id not in sender_store:
sender_store[sender_id] = {"paused": True, "replies": []}
## poll on replies to fetch the message
while len(sender_store[sender_id]["replies"]) == 0:
time.sleep(1)
message = sender_store[sender_id]["replies"].pop(0)
print("Message",message)
return jsonify({"message": message})
if __name__ == "__main__":
app.run(host=app.config.get("HOST"), port=app.config.get("PORT"))