slackapi / python-slack-sdk

Slack Developer Kit for Python
https://tools.slack.dev/python-slack-sdk/
MIT License
3.86k stars 835 forks source link

How to generate Slack button with manifest file? #1019

Closed Harshg999 closed 3 years ago

Harshg999 commented 3 years ago

Hi everyone!

First of all, a big thanks for the new App Manifest feature for Slack Apps!

Since I am new to it and also don't know if this is the right place to ask doubt regarding its documentation, do let me know where can I ask about it.

I was not able to understand how to encode the manifest file in the URL for a Slack button. What needs to be given in <manifest-here> in the URL?

I have the link to the manifest file or I can get the content of it, but not sure how to proceed next.

Thanks in advance!

The page URLs

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

seratch commented 3 years ago

Hi @Harshg999, thanks for asking the question!

Here is an example for https://api.slack.com/tutorials/tracks/actionable-notifications:

https://api.slack.com/apps?new_app=1&manifest_yaml=_metadata%3A%0A++major_version%3A+1%0A++minor_version%3A+1%0Adisplay_information%3A%0A++name%3A+Yogi%0A++description%3A+An+example+app%0A++long_description%3A+An+example+app+that+can+display+actionable+notifications+in+Slack.+App+contains+all+the+necessary+scopes+to+find+a+channel+for+publishing%2C+and+to+publish+a+message.+Enables+Interactivity+features+to+handle+use+of+the+interactive+elements+of+the+notification.+Used+with+tutorials+on+api.slack.com%2Ftutorials.%0A++background_color%3A+%22%23da3a79%22%0Afeatures%3A%0A++bot_user%3A%0A++++display_name%3A+Yogi%0Asettings%3A%0A++interactivity%3A%0A++++is_enabled%3A+true%0A++++request_url%3A+https%3A%2F%2Fexample.com%2Fslack%2Fmessage_action%0Aoauth_config%3A%0A++scopes%3A%0A++++bot%3A%0A++++++-+channels%3Aread%0A++++++-+chat%3Awrite%0A++++++-+chat%3Awrite.public%0A++redirect_urls%3A%0A++++-+https%3A%2F%2Fexample.com%2Fslack%2Fauth%0A

You can use urllib.parse.quote_plus to convert a string data into a URL encoded one.

$ python

>>> from urllib.parse import quote_plus
>>> quote_plus(input())
_metadata:
  major_version: 1
  minor_version: 1
display_information:
  name: Yogi
  description: An example app
  long_description: An example app that can display actionable notifications in Slack. App contains all the necessary scopes to find a channel for publishing, and to publish a message. Enables Interactivity features to handle use of the interactive elements of the notification. Used with tutorials on api.slack.com/tutorials.
  background_color: "#da3a79"
features:
  bot_user:
    display_name: Yogi
settings:
  interactivity:
    is_enabled: true
    request_url: https://example.com/slack/message_action
oauth_config:
  scopes:
    bot:
      - channels:read
      - chat:write
      - chat:write.public
  redirect_urls:
    - https://example.com/slack/auth
'_metadata%3A%0A++major_version%3A+1%0A++minor_version%3A+1%0Adisplay_information%3A%0A++name%3A+Yogi%0A++description%3A+An+example+app%0A++long_description%3A+An+example+app+that+can+display+actionable+notifications+in+Slack.+App+contains+all+the+necessary+scopes+to+find+a+channel+for+publishing%2C+and+to+publish+a+message.+Enables+Interactivity+features+to+handle+use+of+the+interactive+elements+of+the+notification.+Used+with+tutorials+on+api.slack.com%2Ftutorials.%0A++background_color%3A+%22%23da3a79%22%0Afeatures%3A%0A++bot_user%3A%0A++++display_name%3A+Yogi%0Asettings%3A%0A++interactivity%3A%0A++++is_enabled%3A+true%0A++++request_url%3A+https%3A%2F%2Fexample.com%2Fslack%2Fmessage_action%0Aoauth_config%3A%0A++scopes%3A%0A++++bot%3A%0A++++++-+channels%3Aread%0A++++++-+chat%3Awrite%0A++++++-+chat%3Awrite.public%0A++redirect_urls%3A%0A++++-+https%3A%2F%2Fexample.com%2Fslack%2Fauth'
>>>
Harshg999 commented 3 years ago

Thank you @seratch for the answer!