LoginSignup
3
3

More than 5 years have passed since last update.

lita で slack attachment を使う

Last updated at Posted at 2016-02-06

はじめに

lita-slack 1.6.0 以上で slack attachments を使うことが出来る

https://github.com/litaio/lita-slack/releases/tag/v1.6.0
https://api.slack.com/docs/attachments

方法

今回は lita-echo handler を作った
https://github.com/mayok/lita-echo

echo.rb
module Lita
  module Handlers
    class Echo < Handler
      route(/^echo\s+(.+)/, :echo, help: {"echo TEXT" => "Echoes back TEXT"})

      def echo(response)
        text = response.matches[0][0]
        target = response.room
        attachment = Lita::Adapters::Slack::Attachment.new(
          text, {
            color: "#36a64f",
            pretext: "Optional text that appears above the attachment block",
            author_name: "Bobby Tables",
            title: "Slack API Documentation",
            title_link: "https://api.slack.com/",
            text: text,
            fields: [
              {
                title: "Priority",
                value: "High",
                short: true
              },
              {
                title: "Environment",
                value: "production",
                short: true
              }
            ]
          }
        )

        robot.chat_service.send_attachment(target, attachment)
      end

      Lita.register_handler(self)
    end
  end
end

まとめ

response.reply ではなく,
robot.chat_service.send_attachment(target, attachment) を使うと出来る

雑感

text = response.matches[0][0] てかっこ悪いのでなんとかしたい

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3