Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages with attachments #108

Open
bsmoo opened this issue Jun 23, 2017 · 2 comments
Open

Messages with attachments #108

bsmoo opened this issue Jun 23, 2017 · 2 comments

Comments

@bsmoo
Copy link

bsmoo commented Jun 23, 2017

Is there anyway to send message attachments with buttons such as the below:

{
    "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"
                    }
                }
            ]
        }
    ]
}

And clicking the buttons can send data back to the bot which can be logged in a database or something?

@llimllib
Copy link
Owner

Yes! To send the message you will need to use the slack API instead of just returning a string; the github plugin does this, for example.

So you could do something like:

def on_message(msg, server):
    # here we'll assume that `handle_message` returns the dict above ^^^
    fancy_response = handle_message(msg)
    server.slack.post_message(
            msg['channel'],
            '',
            as_user=server.slack.username,
            **fancy_response)

I haven't actually dealt with handling the responses; I'd have to look at what happens when the user clicks on the buttons. I hope I'll get some free time to look at that soon, but if you dig in first please let me know!

@bsmoo
Copy link
Author

bsmoo commented Jul 4, 2017

Thanks @llimllib - likewise let me know if you come up with anything first. I'm just going to be deploying this to a new environment so need to get everything setup again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants