-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 845adeb
Showing
9 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
*/.DS_Store | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM ruby:2.3-onbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "https://rubygems.org" | ||
|
||
gem 'slack-ruby-client' | ||
gem 'eventmachine' | ||
gem 'faye-websocket' | ||
gem 'httparty' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
eventmachine (1.0.8) | ||
faraday (0.9.2) | ||
multipart-post (>= 1.2, < 3) | ||
faraday_middleware (0.10.0) | ||
faraday (>= 0.7.4, < 0.10) | ||
faye-websocket (0.10.2) | ||
eventmachine (>= 0.12.0) | ||
websocket-driver (>= 0.5.1) | ||
gli (2.13.4) | ||
httparty (0.13.7) | ||
json (~> 1.8) | ||
multi_xml (>= 0.5.2) | ||
json (1.8.3) | ||
multi_xml (0.5.5) | ||
multipart-post (2.0.0) | ||
slack-ruby-client (0.5.1) | ||
faraday | ||
faraday_middleware | ||
gli | ||
json | ||
websocket-driver | ||
websocket-driver (0.6.3) | ||
websocket-extensions (>= 0.1.0) | ||
websocket-extensions (0.1.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
eventmachine | ||
faye-websocket | ||
httparty | ||
slack-ruby-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# starter-ruby-bot | ||
|
||
## Overview | ||
Please visit the [Beep Boop Overview](https://beepboophq.com/docs/article/overview) to get the scoop on the the Beep Boop hosting platform and the role of the bot.yml and Dockerfile files. | ||
|
||
Slack API documentation is [here](https://api.slack.com/) | ||
|
||
## Usage: | ||
|
||
... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require 'slack-ruby-client' | ||
|
||
Slack.configure do |config| | ||
config.token = ENV['SLACK_TOKEN'] | ||
fail 'Missing ENV[SLACK_TOKEN]!' unless config.token | ||
end | ||
|
||
client = Slack::RealTime::Client.new | ||
|
||
# listen for hello (connection) event - https://api.slack.com/events/hello | ||
client.on :hello do | ||
puts "Connected '#{client.self['name']}' to '#{client.team['name']}' team at https://#{client.team['domain']}.slack.com." | ||
end | ||
|
||
# listen for channel_joined event - https://api.slack.com/events/channel_joined | ||
client.on :channel_joined do |data| | ||
if joiner_is_bot?(data) | ||
client.message channel: data['channel']['id'], text: starter_text | ||
else | ||
puts "Someone far less important than #{client.self['name']} joined #{data['channel']['id']}" | ||
end | ||
end | ||
|
||
# listen for message event - https://api.slack.com/events/message | ||
client.on :message do |data| | ||
|
||
case data['text'] | ||
when 'hi', 'bot hi' then | ||
client.typing channel: data['channel'] | ||
client.message channel: data['channel'], text: "Hello <@#{data['user']}>." | ||
|
||
if direct_message?(data) | ||
client.message channel: data['channel'], text: "I feel like I've known you forever." | ||
end | ||
|
||
when 'attachment', 'bot attachment' then | ||
# attachment messages require using web_client | ||
client.web_client.chat_postMessage(post_message_payload(data)) | ||
|
||
when bot_mentioned(client) | ||
client.message channel: data['channel'], text: 'You really do care about me. :heart:' | ||
end | ||
end | ||
|
||
def direct_message?(data) | ||
# direct message channles start with a 'D' | ||
data['channel'][0] == 'D' | ||
end | ||
|
||
def bot_mentioned(client) | ||
# match on any instances of `<@bot_id>` in the message | ||
/\<\@#{client.self['id']}\>+/ | ||
end | ||
|
||
def joiner_is_bot?(data) | ||
/^\<\@#{client.self['id']}\>/.match data['channel']['latest']['text'] | ||
end | ||
|
||
def starter_text | ||
%Q("Hello, I'm the BeepBoop starter bot. I don't do much yet, but I would like it if you talked to me anyway: \n | ||
`bot hi`\n | ||
`bot attachment`\n | ||
`@<your bot\'s name>`\n) | ||
end | ||
|
||
def post_message_payload(data) | ||
main_msg = 'Beep Beep Boop is a ridiculously simple hosting platform for your Slackbots.' | ||
{ | ||
channel: data['channel'], | ||
as_user: true, | ||
attachments: [ | ||
{ | ||
fallback: main_msg, | ||
pretext: 'We bring bots to life. :sunglasses: :thumbsup:', | ||
title: 'Host, deploy and share your bot in seconds.', | ||
image_url: 'https://beepboophq.com/bot-1.22f6fb.png', | ||
title_link: 'https://beepboophq.com/', | ||
text: main_msg, | ||
color: '#7CD197' | ||
} | ||
] | ||
} | ||
end | ||
|
||
client.start! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Beepboop Starterbot | ||
description: A simple Ruby bot sample for Beep Boop | ||
avatar: images/avatar.png | ||
background: images/background.png | ||
config: | ||
- name: OPTION | ||
friendly_name: Some Unnecessary Option | ||
info: This is an unnecessary option | ||
default: the default value | ||
- name: SECRET | ||
friendly_name: Shhhh | ||
info: This is an secret option | ||
type: secret | ||
default: not secret though | ||
screenshots: | ||
- screenshot: images/screenshot1.png | ||
- screenshot: images/screenshot2.jpg |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.