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

Edit last message #91

Closed
lukerollans opened this issue Oct 28, 2014 · 11 comments
Closed

Edit last message #91

lukerollans opened this issue Oct 28, 2014 · 11 comments

Comments

@lukerollans
Copy link

Much the same as pressing Up (or of course, clicking "Edit") to edit the last message, I'm wondering if it's possible to do that programmatically within hubot or the adapter.

Would be stellar if it's possible.

Does anyone have any ideas?

@erunion
Copy link
Contributor

erunion commented Oct 28, 2014

Curious: what use case do you have for this?

@lukerollans
Copy link
Author

When a deployment is underway for example, it would be great for our Hubot to send back status updates within the same chunk of text on screen. It would also allow the use of one preformatted block which will make his output cleaner and skinnier

@turnguard
Copy link

are there any news on that one?

i would have another use case :

i'd like to be able to add tags to a message, but sending the original message to a keyphrase extraction service and update the original message with found keywords..

wkr turnguard

@lukerollans
Copy link
Author

Sounds cool.

The new adapter is dropping soon, hopefully we'll see something like this in there. Would be fantastic for ongoing updates that take a long time, rather than spamming messages one after the other.

@paulhammond
Copy link
Contributor

As I mentioned over in #16 the API used by the new adapter supports this - but we haven't yet built support into hubot-slack, mostly because we've not worked out how it would work in the context of hubot. Suggestions are welcome!

@fabianthoma
Copy link

👍 This would be such an awesome feature

On to implementation ideas: Maybe you could return the message object you send to the server and give it methods to update and delete the text. It would probably need changes in your node-slack-client as well, but it shouldn't be too big of a change.
I'm not sure about garbage collection on these message objects though, but they should stick around as long as a hubot script is keeping them referenced.

@paulhammond
Copy link
Contributor

thanks to slackapi/node-slack-sdk#14, the next version of node-slack-client will have the ability to edit messages. The only question left is how we'd implement this inside hubot's framework!

@fabianthoma
Copy link

As I've already commented on my pull request on node-slack-client, you get
the message object passed back, thanks to coffee script awesomeness you get
it passed through all hubot and node-slack-client methods, not entirely
sure if I changed something in hubot-slack, I'll check that when I get home.
You'd then just save the message object and modify it when you need to.
Am 31.01.2015 02:03 schrieb "Paul Hammond" [email protected]:

thanks to slackapi/node-slack-sdk#14
slackapi/node-slack-sdk#14, the next version
of node-slack-client will have the ability to edit messages. The only
question left is how we'd implement this inside hubot's framework!


Reply to this email directly or view it on GitHub
#91 (comment).

@id0Sch
Copy link

id0Sch commented Dec 25, 2016

@paulhammond hi, just wondering; was this ever implemented? if not, how can I use it anyways?
I couldn't find a way and i really need to update sent messages
thanks

@gonstr
Copy link

gonstr commented Apr 13, 2018

Would also really like to know how to update messages. Been digging through documentation and PRs and can't figure out how.

@aoberoi
Copy link
Contributor

aoberoi commented Apr 13, 2018

i can shed some light on this. there's two problems that i see:

  1. this adapter uses the RTM API for Slack. the only way to update a message is to use Web API method chat.update.
  2. in order to use chat.update, you must know the message's channel and ts properties.

the first problem is pretty easy to solve, because you can create your own WebClient object. first you would npm install --save @slack/client in your project, then add a few lines into your script, like so:

# import the Web client code from the node-slack-sdk
{WebClient} = require '@slack/client'

module.exports = (robot) ->
  # instantiate a Web client using the same bot token as the internal RTM client
  web = new WebClient(robot.adapter.client.rtm.token)

  # the rest of your script follows...

the second problem is a little harder to solve. once a message is already sent, the adapter needs to return that message to your code so you can use the channel and ts values. unfortunately, the adapter doesn't currently support this, but its close. it looks like the SlackBot#send method needs to detect whether the last item in messages... is a function, and if so use that as the callback. i think its worth making a new issue to track this feature, so i'm opening #473.

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

8 participants