sock2rtm

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 16 Imported by: 0

README

sock2rtm

SlackのSocketModeで受信したmessage eventをRTMのように配信するWebSocketサーバー(proxy)です。

sock2rtm -h
Usage of sock2rtm:
  -debug
        debug mode
  -port int
        port number (default 8888)
  -version
        show version
  • 環境変数 SLACK_BOT_TOKENSLACK_APP_TOKEN が必要です
  • botを動かすSlack Appには以下のOAuth scopeが必要です
    • channels:history
    • channels:read
    • users:read

API

/start/{channel_id_1},{channel_id_2}.../{client_id}

Slackの/api/rtm.start(廃止済み)を模したレスポンスを返します。

URL pathに指定したチャンネルID(,区切りで複数指定可能)にいるmemberの情報を取得して、レスポンスのusersに含めます。

URL pathにはクライアントの識別子(client_id)を付与できます。同一のclient_idを持った接続に対しては、メッセージは1つのクライアントにしか配信されません。

$ curl http://localhost:8888/start/C7MK19D7F,C0ATSF2MF/my_client_id
{
  "ok": true,
  "url": "ws://localhost:8888/websocket/C7MK19D7F,C0ATSF2MF/my_client_id", // WebSocket接続用URL
  "users": [{...}, {...},....], // ユーザー情報
}
  • PerlのAnyEvent::SlackRTM を使用する場合、$AnyEvent::SlackRTM::START_URL をこのAPIのURLに書き変えてください
  • bot自身はチャンネルへのjoinは行いません。必要なチャンネルへinviteしてください
/websocket/{channel_id_1},{channel_id_2}.../{client_id}

SlackのRTMのようにwebsocketでメッセージを配信します。

  • 配信されるのはmessage eventのみです
  • (botがjoinしているチャンネルのうち)URLで指定したチャンネルのメッセージのみ配信されます
/metrics

メトリクスをJSON形式で出力します。

{
  "slack": {
    "hello": 1,
    "connecting": 1,
    "connected": 1,
    "disconnect": 0
  },
  "websocket": {
    "total_connections": 9,
    "current_connections": 1
  },
  "messages": {
    "received_from_slack": 0,
    "delivered_to_websocket": 0,
    "unsupported_from_slack": 0,
    "write_errored_to_websocket": 0
  }
}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(port int) (*App, error)

func (*App) Run

func (app *App) Run(ctx context.Context)

type Message added in v0.0.2

type Message interface{}

type Metrics added in v0.0.5

type Metrics struct {
	Slack struct {
		Hello      int64 `json:"hello"`
		Connecting int64 `json:"connecting"`
		Connected  int64 `json:"connected"`
		Disconnect int64 `json:"disconnect"`
	} `json:"slack"`
	WebSocket struct {
		TotalConnections   int64 `json:"total_connections"`
		CurrentConnections int64 `json:"current_connections"`
	} `json:"websocket"`
	Messages struct {
		Received     int64 `json:"received_from_slack"`
		Delivered    int64 `json:"delivered_to_websocket"`
		Unsupported  int64 `json:"unsupported_from_slack"`
		WriteErrored int64 `json:"write_errored_to_websocket"`
	} `json:"messages"`
}

type PubSub

type PubSub struct {
	Subscribers map[string]*Subscriber
	// contains filtered or unexported fields
}

func NewPubSub added in v0.0.2

func NewPubSub() *PubSub

func (*PubSub) Close

func (p *PubSub) Close()

func (*PubSub) Publish

func (p *PubSub) Publish(msg Message)

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(clientID string, filter func(Message) bool) *Subscriber

func (*PubSub) Unsubscribe

func (p *PubSub) Unsubscribe(id string)

type StartResponse

type StartResponse struct {
	OK    bool         `json:"ok"`
	URL   string       `json:"url"`
	Users []slack.User `json:"users"`
}

type Subscriber

type Subscriber struct {
	ID          string
	C           chan Message
	Unsubscribe func()
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL