slack-go / slack

Slack API in Go, originally by @nlopes; Maintainers needed, contact @parsley42
https://pkg.go.dev/github.com/slack-go/slack
BSD 2-Clause "Simplified" License
4.69k stars 1.14k forks source link

Error: MessageAction unmarshalling failed. #596

Open oscarzhou opened 5 years ago

oscarzhou commented 5 years ago

This problem happens when the interactive callback is triggered, the program parses the payload of the incoming request. The error is located in slackevents.ParseActionEvent().

In slackevents.ParseActionEvent() function, it uses the struct slackevents.MessageAction as the target struct, which is only compitible with AttachmentAction, but BlockAction. Unfortunately, my payload includes BlockAction.

AttachmentAction json sample:

"actions": [
                {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                }
]

The good thing is that the InteractionCallback struct has defined to compatible with both AttachmentAction and BlockAction.

BlockAction json sample:

   "actions":[ 
      { 
         "action_id":"action123",
         "block_id":"block123",
         "text":{ 
            "type":"plain_text",
            "text":"Reply to me",
            "emoji":true
         },
         "type":"button",
         "action_ts":"1569304306.968465"
      }
   ]

In order to take advantages of the workflow of verifying the token in slackevents.ParseActionEvent(), I will simply replace MessageAction with slack.InteractionCallback in this function to fix the error in my PullRequest.

abgault commented 3 years ago

Did you make a pull request? I have just run into this 2 years later.