hubot-mattermost
hubot-mattermost copied to clipboard
sending Message Attachments
I want to send Message Attachments to mattermost server from hubot i tried with res.send() and res.reply() but it's not working. https://docs.mattermost.com/developer/message-attachments.html?highlight=attachment
how can i send it?
@akki005 Did you get it to work? Would like to use attachments, too
Any idea? I have the same problem.
I got it to work:
module.exports = (robot) ->
robot.hear /myTriggerWord/i, (res) ->
# Creating attachments
attachment1 = {
"fallback": "test",
...
}
attachments = [attachment1, attachment2, ...]
# Create the message for mattermost
msg = {}
# Room is important, but in an .hear you know it already
msg.room = res.envelope.room
msg.attachments = attachments
# Use robot.emit, not res.send or res.reply
robot.emit 'slack.attachment', msg
Hope that's enough.
Could you share a full example? I'm blocked, I've done a case following your example but it doesn't allow me to run Hubot.
Thank you for your answer (I'm desperate).
Sorry, this is a full example. Of course I didn't write out the full attachment stuff, but my example should get you going
Yes, Thank you very much @meilon
I was able to create an attachment with buttons following your example and the documentation of the Mattermost API.
My problem is that I don't know how to do it so that the buttons can interact with Hubot when it comes to being clicked by the user.
I don’t think that this would be possible, hubot is a chat bot, so the user has to say something for hubot to get new input
Yes, that's exactly what I want you to do.
When the user clicks on the button, execute the command that he needs hubot.
For example:
module.exports = (robot) ->
robot.hear /bot (start|hello)/i, (res) ->
attachment0 = {
"author_name": "Bot",
"title": "Welcome",
"text": "Welcome a Test Bot. ¿What can I do for you? ",
"callback_id": "welcome",
"color": "#65c78e",
"actions": [
{
"name": "Test 1",
"integration": {
"url": "http://127.0.0.1:8080/hubot/incoming",
"context": {
"action": "test1"
}
}
},
{
"name": "Test 2",
"integration": {
"url": "http://127.0.0.1:8080/hubot/incoming",
"context": {
"action": "test2"
}
}
}
]
}
attachments = [attachment0]
msg = {}
msg.room = res.envelope.room
msg.attachments = attachments
robot.emit 'slack.attachment', msg
When the user clicks on the "Test 1" button, what I want is for him to post in Mattermost "Bot Test1" and for Hubot to respond to this new command.
The problem is that I don't know how to make that post to the chat through the button and hubot.
Hi there,
robot.emit 'slack.attachment', msg
did not work for me.
However I figured out that
res.send data
at the end works perfectly.
Full example:
robot.respond /sometext to trigger (.*)/i, (res) ->
data = {
"message": "msg",
"props": {
"attachments": [
{
"pretext": "This is the attachment pretext.",
"text": "This is the attachment text.",
"actions": [
{
"name": "Ephemeral Message",
"integration": {
"url": "http://127.0.0.1:7357",
"context": {
"action": "do_something_ephemeral"
}
}
}, {
"name": "Update",
"integration": {
"url": "http://127.0.0.1:7357",
"context": {
"action": "do_something_update"
}
}
}
]
}
]
}
}
res.send data