Your action's 'action_humanagent' run method returned an invalid event. Event will be ignored. Event: 'ConversationPaused()'

Rasa version :

Rasa X version (if used & relevant): 0.13.7

Python version : 3.6.5

Operating system : Win 10

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()'

Please help me out

Thank you!!

did you import the event first?

Thank you for reply

Yes I had import following thing. Is it right?

it should be from rasa_sdk.events

4 Likes

@sushilr007 could you share api.py file?

@ravikrcs

You mean this one ?

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"))

yes, we have to change in api file.

@ravikrcs Is you code working successfully ?

No, i am working on that.

What a wonderful topic. I am having a few trouble matter. It helps me very much

@ravikrcs , is there any update on this? I am stuck at this. Where do we need to change the api file? and what is the change?