Coder Social home page Coder Social logo

scala-slack-bot's Introduction

scala-slack-bot

Codacy Badge

Copy application.conf as secret.conf and fill the gaps.

api.key - slack integration key websocket.key - encoded base64 UUID, for unique websocket connection

##How to Listen

Extend OutgoingMessageListener or IncomingMessageListener, first if you want catch everything sent from other listeners, second if you want to catch everything from channel. All you match inside match block is what you want to catch.

##how to catch message

You need to listen to BaseMessage case class.

##How to find command?

If your bot has name zizzi and command links with params delete 1 you can call it in this ways:

$links delete 1 @zizzi links delete 1 @zizzi: links delete 1

all these things will be translated into object: Command("links", List("delete", "1"), um) um - is underlaying BaseMessage object for additional info.

##How to send message?

use publish function inside listeners.

##What can I send?

There are two types of messages you can send.

If you want to send basic, plain message use OutboundMessage case class. It has two arguments: channel and message.

publish(OutboundMessage(channel, s"hello <@$user>, welcome"))

If you add colors or line breaks, you can send enriched message. To do so, you need to send message to channel with one or more attachments:

Rich message example

on this image you see RichMessage with 3 attachments, each of these attachments has its own color. If don't define color explicitly displayed is grey, what is seen in second attachment.

Attachment can be build from:

  • PreText - text block before colored block,
  • Title - bold text in first line of colored block, you can optionally add URL if you want title as link.
  • Text - text displayed under the title
  • Color - color of left border of block, you can use any in hex format #RRGGBB or predefined: Color.good, Color.warning or Color.danger
  • Field - you can add as many Fields as you want. Every field is build from title, value and boolean value that describe the field should be displayed one per row. Title of Field is displayed as bold text.
  • ImageUrl - url to the image that should be attached to message
    In the example above there are 4 fields described. First and 4th are long (one per row) and the 2nd & 3rd are short(placed in one row).

You can use any combination of these.

Code for example above:

publish(RichOutboundMessage(m.channel, List(
        Attachment(
          Title("Hello title, should be link to Scalac's page", Some("http://scalac.io")),
          Color.danger,
          PreText("this is PreText"),
          Text("Now I'm talking with color and blocks"),
          Field("Field 1", "fill entire row", short = false),
          Field("Field 2", "fill half of the row", short = true),
          Field("Field 3", "fill half od the row", short = true),
          Field("Field 4", "fill entire row")
        ),
        Attachment(Title("Good message"), Text("something like that")),
        Attachment(Color.warning, Field("Teraz field", "taka sytuacja"))
      )
      )
      )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.