Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-skud committed Jan 13, 2016
0 parents commit 845adeb
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
*/.DS_Store
.env
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ruby:2.3-onbuild
6 changes: 6 additions & 0 deletions Gemfile
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'
36 changes: 36 additions & 0 deletions Gemfile.lock
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
11 changes: 11 additions & 0 deletions README.md
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:

...

85 changes: 85 additions & 0 deletions bot.rb
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!
17 changes: 17 additions & 0 deletions bot.yml
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
Binary file added images/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 845adeb

Please sign in to comment.