1

I am creating a Post.message to Slack through Python and want to add in a button feature. I want the button to provide a list of serial numbers that are represented by low2 = low["serials"]. This is the code I currently have and it adds the button to the slack message but when I click the button I get an error saying "Oh no, something went wrong. Please try that again." from slackbot. I saw posts saying that most people have to create a bot to fix their problems with buttons but if the button just has to read this variable I assume there is a way around that. Thanks for the help!

"fields": [
                {
                    "title": "Amount Used:",
                    "value": low1,
                    "short": 'true'
                },{
                    "title": "Distinct Device ID's:",
                    "value": out1,
                    "short": 'true'
                },
                {
                    "title": "Total Connection Time (hr):",
                    "value": data2,
                    "short": 'true'
                }
            ],
           "actions": [
                {
                    "name": "game",
                    "text": "Serials",
                    "type": "button",
                    "value": "serials",
                }
            ],
W. Stephens
  • 729
  • 5
  • 17
  • 31

2 Answers2

1

No, there is no way around it. You must create a Slack App (or "Internal Integration") in order to use buttons in your app. One reason is that you need to tell Slack what URL to call if someone clicks a button (your "Action URL") and that can only by configured as part of a Slack app. Check out this documentation on interactive messages for details.

Regarding your approach. A button will only display one value to the user. If your aim is to let the use choose from a list of serial numbers, you have two options in my opinion:

a) Create a group of buttons, one for each serial number

b) Use an interactive menu to create a drop-down menu for your list

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
0

I solved my problem by converting the confirm action button to display the values I wanted.

with open('Count_BB_Serial_weekly.json', 'r') as lowfile:
      low = json.load(lowfile)

low1 = low["total_serials"]
low2 = low["serials"]
low3 = '\r\n'.join(low2)

Above is my script that imports the array and reads the values. Below I put the results into the "confirm" pop up button.

 ],
       "actions": [
            {
                "name": "game",
                "text": "Serials",
                "type": "button",
                "value": "serials",
                "confirm": {
                    "title": "Serial Numbers",
                    "text": low3,
                    "ok_text": "Yes",
                    "dismiss_text": "No"
                }
        }],
W. Stephens
  • 729
  • 5
  • 17
  • 31