1

I'm building a slash command. The flow I imagine is:

  1. User triggers slash command in client
  2. My server handles request and returns interactive dropdown
  3. User selects option from dropdown in client
  4. My server handles the POST request from the selection and returns an interactive button
  5. User presses the button

Something seems to go wrong between steps 4 and five. The server handles the selection and returns the desired response:

{ 
  "update": {"message": "Updated!"}, 
  "ephemeral_text": "You updated the post!", 
  "attachments": [{
    "text": "Ready?", "actions": [{
      "name": "Go!", 
      "integration": {
        "url": "https://somewhere.com?foo=bar"
        "context": {"action": "event_submitted"}
      }
    }]
  }]
}

...but nothing shows up in the client.

Is something wrong with that JSON? I have tried other things like only returning a text message.

I wonder, if I have misunderstood the docs and the client will never even evaluate a response from a POST triggered by an interactive message. In that case I would have to make a new request back from my server to the Mattermost API in order to get to the next step in my workflow. Is that correct?

EagleBeak
  • 6,939
  • 8
  • 31
  • 47
  • do you see something in Mattermost logs? Set level to `DEBUG`. – Harshil Sharma Jul 22 '19 at 05:10
  • @HarshilSharma, I tried by now. There's really nothing there besides web requests from `web/handlers.go` and the constant complaints about missing CSRF headers described [here](https://forum.mattermost.org/t/csrf-header-error-message-after-every-request/7683/3). – EagleBeak Jul 25 '19 at 11:13
  • Since Mattermost 5.12 Mattermost requires a CSRF token to be present in every POST request. You'd need to add that in you requests. – Harshil Sharma Jul 25 '19 at 11:28
  • @HarshilSharma Really? I thought that feature was still experimental and is off by default. Could you kindly point me a source for that information. – EagleBeak Jul 25 '19 at 12:16
  • Actually, I take that back. You're correct, it's not yet enforced. – Harshil Sharma Jul 25 '19 at 23:16

2 Answers2

2

I misunderstood how Mattermost works in this case. You can't handle a POST from Mattermost and return another interactive button, because Mattermost doesn't evaluate the response body. You have to make a request to the API (or a Webhook) to continue.

EagleBeak
  • 6,939
  • 8
  • 31
  • 47
2

It is possible to update the attachments on a POST from Mattermost. The relevant section in the documentation: How do I manage properties of an interactive message?. The solution is to wrap the new attachment inside update.props like so:

{
    "update": {
        "message": "Updates messsage",
        "props": {
            "attachments": [
                {
                    "text": "Updated attachment text",
                    "actions": [
                        {
                            "name": "Updated action.",
                            "integration": {
                                "url": "...",
                                "context": {
                                    "action": "do something"
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}
bfontaine
  • 18,169
  • 13
  • 73
  • 107
Rayne
  • 2,620
  • 20
  • 28