Mattermost + Hubot (interactive Buttons)

Hi,

I’m assembling a bot with hubot and mattermost and I wanted to know if there is the possibility that hubot can perform actions through the interactive buttons of mattermost so that the user doesn’t need to type the command.

I have not been able to make requests through the action buttons given through an example I have prepared.

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

Can someone help me or confirm whether this is possible or not?

Hi @Fabianski-tr! Thank you for reaching out.

Is this the one you are using: https://github.com/renanvicente/hubot-mattermost? If yes, it might be best to directly contact the maintainers / creators of the bot as they might be most familiar with your question!

You can also use alternatives for interactive buttons, here are some instructions: https://docs.mattermost.com/developer/interactive-message-buttons.html.

OK, thank you!
But, Can I trigget a slash command by clicking the button, insted of sending a POST request to an integration?

maybe something like:

{
  "attachments": [
    {
      "text": "This is the attachment text.",
      "actions": [
        {
          "name": "Create Issue",
          "slash": {
            "command": "/newissue there is a bug" 
          }
        }
      ]
    }
  ]
}

@Fabianski-tr

I started work on a fork of hubot-mattermost that supports attachments. I’m using it for my own integrations.

Take a look at https://github.com/thejimnicholson/hubot-mattermost-with-attachment

Great! I’m trying your adapter.
Do you have a complete example to send attachments that responds to the action?

This is my attachment test with mattermost adapter:

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

Here’s an example using my adapter:

module.exports = (robot) -> 
 robot.respond /give me an attachment/i, (res) ->
  envelope =
    username: 'TheBoss'
    channel: res.envelope.room
    icon_url: 'http://www.someiconfarm.com/theboss.png'
    attachments: [
      color: "#000080"
      text: "Here's a blue one."
      fallback: "Here's a blue one that you can't see."
    ]
  robot.send envelope, "Message with attachments"

Essentially, what my changes to the adapter do is let you set more properties on the envelope that you pass to robot.send. The original adapter only respected properties on envelope that affected the channel to which the response was sent.

What I did shouldn’t break other things, but it might have some odd interactions in cases where code was passing an envelope to send, because the old adapter would ignore anything in the envelope except .room and .user.room.

If you see things in my code that you think you need to change, please feel free to send me a PR on github.

Now I get it to show correctly just like the example I did with the renanvicente connector.

But, I have the same problem I indicated. I cannot associate actions of the attachment buttons to execute commands on hubot or Mattermost’s custom slash commands.

I’ve not played with the button stuff yet; I’ll give it a try when I get a few spare cycles.