0
votes

I'm attempting to invoke my api which is self hosted via ngrok. ngrok is working correctly because I can open the external https site in my browser and it loads up.

So, what do I have

slack form:

var request = require('request');

var RegisterMsgBuilder = function () { }

RegisterMsgBuilder.prototype.build = function (data) {
return {
    "text": "Would you like to play a game?",
    "attachments": [
        {
            "text": "Choose a game to play",
            "fallback": "You are unable to choose a game",
            "callback_id": "wopr_game",
            "color": "#3AA3E3",
            "attachment_type": "default",
            "actions": [
                {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                },
                {
                    "name": "game",
                    "text": "Falken's Maze",
                    "type": "button",
                    "value": "maze"
                },
                {
                    "name": "game",
                    "text": "Thermonuclear War",
                    "style": "danger",
                    "type": "button",
                    "value": "war",
                    "confirm": {
                        "title": "Are you sure?",
                        "text": "Wouldn't you prefer a good game of chess?",
                        "ok_text": "Yes",
                        "dismiss_text": "No"
                    }
                }
            ]
        }
    ]
}
};


exports.RegisterMsgBuilder = RegisterMsgBuilder;

this produces a form in slack with 3 buttons.

I've set up interactive components with the following url: https://xyz.ngrok.io/api/values

this url points to a new asp.net webapi project. I've not changed anything in here. Its got a controller which looks like:

namespace WebApplication2.Controllers
{
public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
        public void Post()
        {
            int x = 66;

        }
    }
}

clicking on a button in my slack message does nothing. How come?

1
What is your application's "action URL" set to? And what do you expect to happen when you click the button? None of your API methods seem to actually do anything. - Matti Virkkunen
thats correct, I have a breakpoint set on the POST method. action url: b3cce8f3.ngrok.io/api/values does the webapi need to authenticate? - John

1 Answers

0
votes

Primarily, you haven't given any kind of response for the API to act on. All your controller seems to do on receiving a POST is set x equal to 66.

When someone clicks that button in-channel, a POST request will be made to your action URL. It'll contain some information about the button clicked, the original message, etc (https://api.slack.com/interactive-messages#responding). You don't seem to be pulling the values from the POST your app receives at all - you'll definitely need to do that.