'Rasa - Facebook connector jumps into infinite loop when sending an audio utterance

I have created a custom facebook connector inherited from the facebook connector provided by Rasa. I want to send the users audio message for their queries, so I have modified the code like below:

class MessengerBotCustom(OutputChannel):
    """A bot that uses fb-messenger to communicate."""

    @classmethod
    def name(cls) -> Text:
        return "facebookcustom"

    def __init__(self, messenger_client: MessengerClient, metadata={}) -> None:

        self.messenger_client = messenger_client
        self.metadata = metadata
        self.last_event_time = None
        
        super().__init__()

    def send(self, recipient_id: Text, element: Any) -> None:
        """Sends a message to the recipient using the messenger client."""

        # this is a bit hacky, but the client doesn't have a proper API to
        # send messages but instead expects the incoming sender to be present
        # which we don't have as it is stored in the input channel.
        self.messenger_client.send(element.to_dict(), recipient_id, "RESPONSE")

    async def send_text_message(
        self, recipient_id: Text, text: Text, **kwargs: Any
    ) -> None:
        """Send a message through this channel."""
        # for message_part in text.strip().split("\n\n"):
        # self.send(recipient_id, FBText(text=text))

        response = run_tts(text,lang='eng', utter_action='')
  
        
        filename = response['file']
        wav_url = f"{SPEECH_SERVER}/static/utterances/{filename}"
        print(wav_url)
        
        self.send(recipient_id, Audio(url=wav_url, is_reusable=False))

Remember, when I use:

self.send(recipient_id, FBText(text=text))

it behaves normal, however, when I change it to following:

self.send(recipient_id, Audio(url=wav_url, is_reusable=False))

I keep receiving the same utterances in audio form until I stop the server.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source