https://github.com/matsub/slashcommands
A tiny framework for slash commands of Slack.
https://github.com/matsub/slashcommands
japronto python slack
Last synced: about 2 months ago
JSON representation
A tiny framework for slash commands of Slack.
- Host: GitHub
- URL: https://github.com/matsub/slashcommands
- Owner: matsub
- License: mit
- Created: 2017-03-18T11:07:39.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T05:22:40.000Z (almost 4 years ago)
- Last Synced: 2026-03-05T05:52:38.236Z (3 months ago)
- Topics: japronto, python, slack
- Language: Python
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://app.wercker.com/project/byKey/b529bb3589c645bc2d0cc4c560acb7ee)
# slashcommands
A tiny framework for slash commands of Slack.
# Installation
with Python 3.6+
```sh
$ pip install slashcommands
```
# Usage
Create a program as below,
```python
from slashcommands import SlashCommands
TOKEN = '--- Your Verification Token Here ---'
app = SlashCommands(TOKEN, prefix='/slack/')
@app.route('/')
def hello(body):
return "hello!"
@app.route('/hey')
def foo(body):
response = {
"text": "What'up @{0} !!".format(body['user_name']),
"response_type": "in_channel",
}
return response
if __name__ == '__main__':
app.run(port=8080)
```
and run it on your server.
The argument `body` is the request from slack. This is typed as a `dict`
object. See the [Documentation of Slack](https://api.slack.com/slash-commands#how_do_commands_work)
for the structure of this request.
## Using modules
As your program gets longer, you may want to split it into several files.
To support it, each `SlashCommands` object can inherit another `SlashCommands`
object like,
```python
app = SlashCommands(TOKEN)
subapp = SlashCommands(TOKEN, prefix='/sub/')
@app.route('/')
def hello(body):
return "hello!"
@subapp.route('/')
def sub(body):
return "I'm subapp!"
app.install(subapp)
```
now `app` object has additional path `/sub/`.