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

Let message.forward() optionally keep the data #63

Open
emphasize opened this issue Dec 7, 2023 · 0 comments
Open

Let message.forward() optionally keep the data #63

emphasize opened this issue Dec 7, 2023 · 0 comments

Comments

@emphasize
Copy link
Member

emphasize commented Dec 7, 2023

Easy thing, sometimes you may want to redirect the message not only with given context, but also the data

def forward(self, msg_type: str, data: dict = None) -> _MsgBase:
"""
Keep context and forward message
This will take the same parameters as a message object but use
the current message object as a reference. It will copy the context
from the existing message object.
Args:
msg_type (str): type of message
data (dict): data for message
Returns:
Message: Message object to be used on the reply to the message
"""
data = data or {}
return Message(msg_type, data, context=self.context)

data = data or self.data or {}

should do the trick. More or less just optics, but feels right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant