Slack Bot Application that uses Pokerap to consume Pokeapi
This is an implementation of Elixir-Slack that queries the http://pokeapi.co/ API using Pokerap . To be a responsible citizen, it uses Poolboy and an ETS cache to keep from hammering the API too hard (they will limit you).
If available in Hex, the package can be installed as:
- Add
slack_professor
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:slack_professor, git: "https://github.com/LastContinue/slack_professor"}]
end
```
- Ensure
slack_professor
is started before your application:
```elixir
def application do
[applications: [:slack_professor]]
end
```
First, you need a Slack Api Token for a bot. You can create this by logging into Slack as an admin, then
going to apps > custom integrations
and there should be a dialog to make a bot. (Or just Google it, probably more detailed)
Using this token, you can create a bot simply by
iex(1)> SlackProfessor.start_bot("your_api_token")
Connected as "<BotName>"
That's it! Your bot should now show up in Slack, and you can invite it to channels, etc.
You can even make multiple bots! This is a good idea if you have multiple Slack orgs because the bots will share the same connection pool and ETS cache (assuming they are ran in the same instance)!
Checkout https://github.com/LastContinue/professor_demo for a demo of one of the many ways you can use this as a stand-alone application.
So you have a bot, great, now what can it do?
Lets say you have a bot named ProfessorOak
@ProfessorOak tell me about Pikachu
and viola facts about Pikachu!
Commands | Description |
---|---|
"tell me about X" | Gets a random flavor text for Pokemon (language can be set, see ENV/Configs section) |
"evolution X" | Gets a very simple evolution chain for a Pokemon |
"show me X" | Gets two sprites for a Pokemon |
"what type is X" | Tells the type of a Pokemon |
That's it for now, but there's a bunch more to add (PR's welcomed!)
You can customize some aspects of your bots depending on your needs. All settings have defaults, so they are optional
Please read up on Poolboy before messing with those settings (I barely understand them)
Env | Desc | Format | Default |
---|---|---|---|
:slack_professor, :timeout |
Timeout for Bot to complete task. Don't set it lower than Pokerap timeout settings | integer (in milliseconds) | 30000 |
:slack_professor, :pool_size |
How many Poolboy workers you have (be cool with this) | integer | 5 |
:slack_professor, :pool_overflow |
Overflow setting for Poolboy | integer | 1 |
:slack_professor, :cache_duration |
How long ETS with cache | integer (in seconds) | 86400 (24 hours) |
Additionally, because this uses Pokerap, you can set ENV settings from that library as well, See
https://github.com/LastContinue/Pokerap#env-settings
for full list (I highly recommend setting :pokerap, :timeout
and :pokerap, :recv_timeout
)
- Customized grammar around the responses (this is stubbed, but not finished)
- More interactions!
- Better formatting for interactions
- Testing!
- Smarter Caching (maybe...this is a thorny issue)