Bot farm of SLACK.
Heaven is higher than a cloud.
This is rails application.
- System Required
- Ruby (>2.0.0)
- Bundler
SLACK_TEAM_ID=[your team id]
SLACK_APP_ID=[your app id]
SLACK_APP_SECRET=[your app secret]
SLACK_BOT_NAME=[your bot name]
SLACK_BOT_TOKEN=[your bot token]
SECRET_KEY_BASE=[any string]
RAILS_SERVE_STATIC_FILES=1 # If you use heroku.
-
Slack Team ID
-
Application Client ID and Client Secret.
- https://api.slack.com/applications
- You should set Redirect URI to
http://{your application host}/auth/slack/callback
.
-
BotName and BotToken
bundle install --path vendor/bundle
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rails s -e production
register
// Set alarm.
// @param [String] alarm_name Name of alarm.
// @param [String] callback Name of callback.
// @param [Integer] minutes Minutes.
// @param [Boolean] repeat Enabled repeat.
api.alarm.register(alarm_name, callback, minutes, repeat)
// Example
api.alarm.register("name", "onAlarm", 1, false)
remove
// Remove alarm.
// @param [String] alarm_name Name of alarm.
api.alarm.remove(alarm_name)
// Example
api.alarm.remove("name")
all
// Example
api.alarm.all()
clear
// Example
api.alarm.clear()
GET
// Get request.
// @param [String] url URL
// @param [Hash] params Parameters.
// @param [String] callback Name of callback function.
api.http.get(url, params, callback)
// Example
api.http.get("http://www.google.co.jp/", {}, "onReceive");
POST
// Post request.
// @param [String] url URL
// @param [Hash] params Parameters.
// @param [String] callback Name of callback function.
api.http.post(url, params, callback)
// Example
api.http.post("http://www.google.co.jp/", {}, "onReceive");
Talk
// Talk
// @param [String] message Message
// @param [Hash] options Message
api.slack.talk(message, options = {})
// Example
api.slack.talk("Hello!")
api.slack.talk("with options", {
name: 'my_bot',
icon: ':my_icon:'
})
Talk with icon
// Talk with icon
// @param [String] message Message
// @param [String] icon_emoji Emoji Icon.
api.slack.talk_with_icon(message, icon_emoji)
// Example
api.slack.talk_with_icon("Hello!", "tofu_on_fire")
Set value
// Set value.
// @param [String] key Key
// @param [String] value Value
api.storage[key] = value
// Example
api.storage['name'] = 'alfa'
Get value
// Get value.
// @param [String] key Key
api.storage[key]
// Example
api.storage['name']
Get keys.
// Example
api.storage.keys()
Clear all.
// Example
api.storage.clear()
Get bot name
api.setting.name
Get bot default icon
api.setting.icon
Get joined channel
api.setting.channel
Get creator name
api.setting.user
A bot can hook a request of http://{yourhost}/bots/{bot_id}/hook
.
Code
function onHook(method, params) {
slack.api.talk(params['message'])
}
Request
GET /bots/1/hook?message=hello!
In this case, A Bot will say hello!
.
This project is released under the MIT license.