All Projects → rikas → Slack Poster

rikas / Slack Poster

Licence: mit
Simple gem to post messages on Slack using web hooks.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Slack Poster

Slack Machine
A sexy, simple, yet powerful and extendable Slack bot
Stars: ✭ 91 (+85.71%)
Mutual labels:  bot, slackbot, slack-api, slack
Slacker
Slack Bot Framework
Stars: ✭ 495 (+910.2%)
Mutual labels:  bot, slackbot, slack-api, slack
Slack Block Builder
Lightweight, no-dependency JavaScript library for creating Slack Block Kit UIs, with a builder syntax, inspired by SwiftUI.
Stars: ✭ 129 (+163.27%)
Mutual labels:  slackbot, slack-api, slack
Jbot
Make Slack and Facebook Bots in Java.
Stars: ✭ 1,148 (+2242.86%)
Mutual labels:  bot, slackbot, slack
Whatis
Whatis bot server for Slack!
Stars: ✭ 22 (-55.1%)
Mutual labels:  bot, slack-api, slack
Office Simulator
Miss the office life? You won't any more with this wonderful office slack simulator.
Stars: ✭ 152 (+210.2%)
Mutual labels:  bot, slackbot, slack
Botonomous
A PHP Framework For Creating Autonomous Slack Bots
Stars: ✭ 109 (+122.45%)
Mutual labels:  bot, slackbot, slack
Obed Bot
🍴 Obed Slack Bot, na požiadanie kontroluje aktuálnu ponuku denného menu reštaurácii. [only for slovak|czech users]
Stars: ✭ 32 (-34.69%)
Mutual labels:  bot, slackbot, slack
Sactive Bot
😈 An extensible chat bot framework. sactive-bot is an evolution of the open source hubot project. - https://www.shipengqi.top/sactive-bot .
Stars: ✭ 212 (+332.65%)
Mutual labels:  bot, slackbot, slack
Go Sarah
Simple yet customizable bot framework written in Go.
Stars: ✭ 188 (+283.67%)
Mutual labels:  bot, slackbot, slack
dienstplan
Slack bot app for duty rotations
Stars: ✭ 14 (-71.43%)
Mutual labels:  slack, slackbot, slack-api
Slack Ruby Client
A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
Stars: ✭ 957 (+1853.06%)
Mutual labels:  slackbot, slack-api, slack
Aiva
AIVA (A.I. Virtual Assistant): General-purpose virtual assistant for developers.
Stars: ✭ 693 (+1314.29%)
Mutual labels:  bot, slack
Hedwig
An Adapter-based Bot Framework for Elixir Applications
Stars: ✭ 609 (+1142.86%)
Mutual labels:  bot, slack
Integrations
Connect your App to Multiple Messaging Channels with the W3C Open standard.
Stars: ✭ 721 (+1371.43%)
Mutual labels:  bot, slack
Auto Like My Gf Insta Pic
Bot to automatically like your friend's Instagram post and notify you on Slack
Stars: ✭ 773 (+1477.55%)
Mutual labels:  bot, slack
Elixir Slack
Slack real time messaging and web API client in Elixir
Stars: ✭ 587 (+1097.96%)
Mutual labels:  bot, slack
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+1383.67%)
Mutual labels:  bot, slack
Inventory Hunter
⚡️ Get notified as soon as your next CPU, GPU, or game console is in stock
Stars: ✭ 778 (+1487.76%)
Mutual labels:  bot, slack
Slack Black Theme
slack theme, dark theme for slack, black theme slack black theme
Stars: ✭ 531 (+983.67%)
Mutual labels:  slack-api, slack

Build Status

Slack Poster

slack-poster is a simple gem to make your integration with Slack easier. It supports only incoming communications (from you to Slack).

Installation

Add this line to your application's Gemfile:

$ gem 'slack-poster'

And then execute:

$ bundle

Or install it yourself as:

$ gem install slack-poster

Slack setup

This gem will use a Incoming WebHook integration on Slack. First, you need to create a new Incoming Webhook integration at https://team-name.slack.com/services/new/incoming-webhook (where "team-name" should be your own team name).

Hit "Add Incoming WebHooks Integration" and go to the next screen. Here you can add a name to your integration, customize the username that will post and the icon.

Copy the Webhook URL, because you'll need it. Click "Save Settings" and you're done.

Usage

First you have to initialize your poster and then you can use send_message to send your message.

poster = Slack::Poster.new(YOUR_WEBHOOK_URL)
poster.send_message('Hello world!')

You can use an options array if you don't want to use the default settings:

options = {
  icon_url: 'http://example.com/image.png',
  # or icon_emoji: 'emoji_name',
  username: 'Tester',
  channel: '#random'
}

And then use it as a second parameter. Note that every option is optional (no pun intended!).

poster = Slack::Poster.new(YOUR_WEBHOOK_URL, options)
poster.send_message('Hello with options')
# posts message 'Hello with options' to #random with the username 'Tester'

Or you can change the options whenever you want

poster = Slack::Poster.new(YOUR_WEBHOOK_URL)
poster.username = 'TestUser'
poster.icon_emoji = '👻'
poster.send_message('Hello World') # => "ok"
# posts message 'Hello World' to #random with the username 'TestUser' and ghost emoji as avatar

You can also send a Slack::Message object instead of String:

message = Slack::Message.new('hello slack')
poster.send_message(message)

Message attachments

Slack Poster supports message attachments. To do so you have to create Slack::Attachment objects and then attach them to a Slack::Message object. Read the official documentation to understand how attachments work and see different examples of attachments in practice.

You can build a basic attachment and them attach it to a message and use a poster to post that message for you:

# As an alternative you could also initialize the attachment with all the fields
# Slack::Attachment.new(fallback: 'fallback', pretext: 'pretext', ....)
attachment = Slack::Attachment.new

# This text will be used in clients that don't show formatted text (eg. IRC, mobile notifications)
attachment.fallback = "You wouldn't believe who's a mighty pirate!"

attachment.pretext = 'Arrrgh'
attachment.color = 'danger' # good, warning, danger, or any hex color code (eg. #439FE0)

attachment.image_url = 'https://pbs.twimg.com/profile_images/446438045945180162/KH34Nkuq.jpeg'
# you can use thumb_url instead for a small thumb pulled to the right

attachment.text = 'To become a mighty pirate Guybrush had to go through the three trials.'
attachment.title = 'Mighty pirate'
attachment.title_link = 'http://scummbar.com/'

# If you want to include author information you can use the following methods:
# attachment.author_name
# attachment.author_icon
# attachment.author_link
# Check Slack documentation for more info.

message = Slack::Message.new('Monkey island news', attachment)

# You can also add the attachment after initializing the message:
# message = Slack::Message.new('Monkey island news')
# message.attachments << attachment

poster = Slack::Poster.new(YOUR_WEBHOOK_URL)
poster.username = 'Monkey Island Daily'
poster.icon_emoji = '🐵'
poster.send_message(message) # => "ok"

This will create a message like this one:

Fields

Slack attachment can contain fields that will be displayed in a table inside the message attachment. You can add fields with Slack::Attachment#add_field:

attachment = Slack::Attachment.new
attachment.add_field('Name1', 'Value1')
attachment.add_field('Name2', 'Value2')
attachment.add_field('Name3', 'Value3')
attachment.add_field('Name4', 'Value4')

message = Slack::Message.new('What a beautiful table of names and values', attachment)

poster = Slack::Poster.new(YOUR_WEBHOOK_URL)
poster.send_message(message) # => "ok"

You may notice that the message will display with a vertical list of fields. You can have them side by side giving a third boolean parameter (is it a short field?).

attachment = Slack::Attachment.new
attachment.add_field('Name1', 'Value1', true)
attachment.add_field('Name2', 'Value2', true)
attachment.add_field('Name3', 'Value3')
attachment.add_field('Name4', 'Value4')

This way the first two field will be displayed in the same row.

Contributing

  1. Fork it ( http://github.com/rikas/slack-poster/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].