Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted speed to message length #102

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Rasa_Bot/custom_channels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import os
import time
import typing
from typing import Text, Callable, Awaitable, Any, Dict, List

Expand All @@ -13,6 +14,11 @@


NICEDAY_API_URL = os.getenv('NICEDAY_API_ENDPOINT')
# proportional factor between the number of words in a message and the time to wait before the
# newt message is delivered
WORDS_PER_SECOND = 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, ok, so this is the fix for the PF app spamming users with 6000 messages a minute like a deranged stalker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahahah yes, now it should be less annoying (if possible).

# maximum delay between a message and the next one
MAX_DELAY = 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also units of seconds, I assume?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I'm updating the definition



class NicedayOutputChannel(CollectingOutputChannel):
Expand Down Expand Up @@ -50,10 +56,12 @@ def _message(self, # pylint: disable=too-many-arguments, arguments-renamed
# filter out any values that are `None`
return {k: v for k, v in obj.items() if v is not None}


class NicedayTriggerOutputChannel(OutputChannel):
"""
Output channel that sends messages to Niceday server
"""

def __init__(self):
self.niceday_client = NicedayClient(niceday_api_uri=NICEDAY_API_URL)

Expand All @@ -67,6 +75,10 @@ async def send_text_message(
"""Send a message through this channel."""
for message_part in text.strip().split("\n\n"):
self.niceday_client.post_message(int(recipient_id), message_part)
delay = len(message_part.split(' '))/WORDS_PER_SECOND
delay = min(delay, MAX_DELAY)
time.sleep(delay)


class NicedayInputChannel(InputChannel):
"""
Expand Down