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

Add ability to update slack messages #75

Merged
merged 4 commits into from
Sep 21, 2022
Merged

Conversation

TheJokersThief
Copy link
Contributor

@TheJokersThief TheJokersThief commented Sep 19, 2022

What

  • Add a method to update messages
  • Alter send_message method so that if the message timestamps are present, it will update the message(s) instead

Why

Updating messages is really handy, to communicate status, follow up with feedback, or replace some placeholder text while the bot works on an answer.

Example usage

Here's a basic example of sending an initial message, doing some processing (in this case sleeping) and then updating the original message to avoid clutter in a channel.

@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    first_msg = self._bot.send_message(
        Message(
            to=msg.frm,
            body="Give me a moment while I get that for you!",
        )
    )

    time.sleep(10)

    first_msg.body = "Ah, here we go. The answer is 42"

    updated_msg = self._bot.update_message(first_msg)

Misc

Related to :

@TheJokersThief TheJokersThief marked this pull request as ready for review September 20, 2022 00:03
@sijis
Copy link
Collaborator

sijis commented Sep 20, 2022

Thanks for the contribution.

Would you be able to include some code example on usage of new method within the description of PR?

@TheJokersThief
Copy link
Contributor Author

Yes, of course!

Here's a basic example of sending an initial message, doing some processing (in this case sleeping) and then updating the original message to avoid clutter in a channel.

@botcmd
def hello(self, msg, args):
    """Say hello to someone"""
    first_msg = self._bot.send_message(
        Message(
            to=msg.frm,
            body="Give me a moment while I get that for you!",
        )
    )

    time.sleep(10)

    first_msg.body = "Ah, here we go. The answer is 42"

    updated_msg = self._bot.update_message(first_msg)

@nzlosh nzlosh merged commit 7535b5f into errbotio:main Sep 21, 2022
@nzlosh
Copy link
Collaborator

nzlosh commented Sep 21, 2022

This looks good to me and thank you again for the contribution.

@TheJokersThief TheJokersThief deleted the patch-1 branch September 24, 2022 13:34
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

Successfully merging this pull request may close these issues.

3 participants