Useful Slack Slash Command decorators for AWS Lambda.
Project description
# slash-command-decorator
slash-command-decorator is a simple decorator for the use of AWS Lambda as the [Slack Slash Command](https://api.slack.com/slash-commands) backend.
[![CircleCI](https://circleci.com/gh/penta515/slash-command-decorator.svg?style=svg)](https://circleci.com/gh/penta515/slash-command-decorator) [![Code Climate](https://codeclimate.com/github/penta515/slash-command-decorator/badges/gpa.svg)](https://codeclimate.com/github/penta515/slash-command-decorator)
## Installation
The latest release of slash-command-decorator can be installed via pip
```
$ pip install slash-command-decorator
```
An alternative install method would be manually installing it leveraging `setup.py`
```
$ git clone https://github.com/penta515/slash-command-decorator
$ cd slash-command-decorator
$ python setup.py install
```
## Set Query String in event
In handler function `event.body` parameter, it is necessary to set up URL query string that was tranmitted by Slack
###Example event.body
```python
"token=aCec9XZPS6klbnAAAAAAAAAA&team_id=T0AAAAAAA&team_domain=test-domain&channel_id=C0AAAAAAA&channel_name=general&user_id=U0AAAAAAA&user_name=hoge&command=%2Fcommand&text=hoge&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT0JQU92NA%2F1234567890%2Faaaaaaaaaaaaaaaaaaa"
```
## Usage examples
Usage examples are included in the [samples directory](https://google.co.jp)
```python
from slash_command_decorator.slash_command import SlashCommand
from slash_command_decorator import (
lambda_manager,
respond_to_option
)
SLACK_API_TOKEN = "xoxp-12345678901-12345678901-12345678901-hogefugapiyo"
CONFIG = {
"username": "Slash Command",
"icon_emoji": ":penguin:"
}
@lambda_manager
def lambda_handler(event, context):
@respond_to_option("^help$")
def help_option(reaction):
reaction.ephemeral("HELP!")
@respond_to_option("^hoge$")
def hoge_option(reaction):
reaction.in_channel("HOGE!")
@respond_to_option("^fuga$")
def fuga_option(reaction):
reaction.send("FUGA!")
@respond_to_option("^piyo$")
def piyo_option(reaction):
reaction.reply("PIYO!")
SlashCommand(
token=SLACK_API_TOKEN,
config=CONFIG
).start(
help_option,
hoge_option,
fuga_option,
piyo_option
)
```
###Types of Responses
####1.ephemeral
```python
@respond_to_option("^help$")
def help_option(reaction):
reaction.ephemeral("HELP!")
```
![ephemeral](https://github.com/penta515/slash-command-decorator/blob/develop/images/help.gif)
####2.in_channel
```python
@respond_to_option("^hoge$")
def hoge_option(reaction):
reaction.in_channel("HOGE!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/hoge.gif)
####3.send
```python
@respond_to_option("^fuga$")
def fuga_option(reaction):
reaction.send("FUGA!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/fuga.gif)
####4.reply
```python
@respond_to_option("^PIYO$")
def piyo_option(reaction):
reaction.reply("PIYO!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/piyo.gif)
## Running tests
```
$ py.test tests
```
## License
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
slash-command-decorator is a simple decorator for the use of AWS Lambda as the [Slack Slash Command](https://api.slack.com/slash-commands) backend.
[![CircleCI](https://circleci.com/gh/penta515/slash-command-decorator.svg?style=svg)](https://circleci.com/gh/penta515/slash-command-decorator) [![Code Climate](https://codeclimate.com/github/penta515/slash-command-decorator/badges/gpa.svg)](https://codeclimate.com/github/penta515/slash-command-decorator)
## Installation
The latest release of slash-command-decorator can be installed via pip
```
$ pip install slash-command-decorator
```
An alternative install method would be manually installing it leveraging `setup.py`
```
$ git clone https://github.com/penta515/slash-command-decorator
$ cd slash-command-decorator
$ python setup.py install
```
## Set Query String in event
In handler function `event.body` parameter, it is necessary to set up URL query string that was tranmitted by Slack
###Example event.body
```python
"token=aCec9XZPS6klbnAAAAAAAAAA&team_id=T0AAAAAAA&team_domain=test-domain&channel_id=C0AAAAAAA&channel_name=general&user_id=U0AAAAAAA&user_name=hoge&command=%2Fcommand&text=hoge&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT0JQU92NA%2F1234567890%2Faaaaaaaaaaaaaaaaaaa"
```
## Usage examples
Usage examples are included in the [samples directory](https://google.co.jp)
```python
from slash_command_decorator.slash_command import SlashCommand
from slash_command_decorator import (
lambda_manager,
respond_to_option
)
SLACK_API_TOKEN = "xoxp-12345678901-12345678901-12345678901-hogefugapiyo"
CONFIG = {
"username": "Slash Command",
"icon_emoji": ":penguin:"
}
@lambda_manager
def lambda_handler(event, context):
@respond_to_option("^help$")
def help_option(reaction):
reaction.ephemeral("HELP!")
@respond_to_option("^hoge$")
def hoge_option(reaction):
reaction.in_channel("HOGE!")
@respond_to_option("^fuga$")
def fuga_option(reaction):
reaction.send("FUGA!")
@respond_to_option("^piyo$")
def piyo_option(reaction):
reaction.reply("PIYO!")
SlashCommand(
token=SLACK_API_TOKEN,
config=CONFIG
).start(
help_option,
hoge_option,
fuga_option,
piyo_option
)
```
###Types of Responses
####1.ephemeral
```python
@respond_to_option("^help$")
def help_option(reaction):
reaction.ephemeral("HELP!")
```
![ephemeral](https://github.com/penta515/slash-command-decorator/blob/develop/images/help.gif)
####2.in_channel
```python
@respond_to_option("^hoge$")
def hoge_option(reaction):
reaction.in_channel("HOGE!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/hoge.gif)
####3.send
```python
@respond_to_option("^fuga$")
def fuga_option(reaction):
reaction.send("FUGA!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/fuga.gif)
####4.reply
```python
@respond_to_option("^PIYO$")
def piyo_option(reaction):
reaction.reply("PIYO!")
```
![in_channel](https://github.com/penta515/slash-command-decorator/blob/develop/images/piyo.gif)
## Running tests
```
$ py.test tests
```
## License
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for slash-command-decorator-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf0ce9901d468d95b9a063ad0af0b212806ba0ad6736766c60d912eea28791a3 |
|
MD5 | e212df3276e1bde7a92604d67da04862 |
|
BLAKE2b-256 | 877ea7518c25b8fa4d054ae4ffcb24901d1459db31ddf66ae352abe812cfcc40 |
Close
Hashes for slash_command_decorator-0.0.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be01d01569c0832269ea862f74179d002a4ddbb495a1af389051a3c53931298 |
|
MD5 | bbe3fb5f216dc5c63945ac56a897cfb1 |
|
BLAKE2b-256 | 0a61996588a127ab48d84c42b5ba8e733eaad2094b5d9b2c616d7373e4b04cc4 |