現在RTM APIを使用してScalaで#slackボットを作成しようとしています。#slack「{}」メッセージの後に続くRTM APIの切断
"ping"と "pong"に応答する基本的な機能的なボットを手に入れました。
私が現在経験している問題は、ストリームの開始から数分ごとにwebsocket接続が体系的に閉じられることです。私は現在、WebSocketをのための次のライブラリ使用してい
:この時点でhttps://github.com/jfarcand/WCS
を、私は#slackから受信された空のJSONメッセージ({}
)次の接続のドロップを引き起こしているものを全くわかりませんRTMストリーム。
ご協力いただければ幸いです。ここで
は、関連する接続とリスナーのコードです:ここで
def connect(): Unit ={
if(rec_url == "")
slack = ws.open(rtm_url)
else {
h.debug("Attempting to reconnect")
slack = WebSocket().open(rec_url) // TODO: need to completely close the connection before trying to create a new one.
}
initRTM()
}
// Initialize Real Time Messaging
def initRTM(): Unit = {
h.debug("\nOpening Real Time Messaging socket")
slack.listener(new TextListener {
override def onOpen: Unit = {
h.debug("Websocket connection open")
status = 1
}
override def onClose: Unit = {
h.debug("Websocket connection closed, reconnecting...")
slack.shutDown
status = 0
}
override def onError(t: Throwable): Unit ={
h.debug("Websocket Error encountered")
t.printStackTrace()
h.debug(t.getMessage)
}
override def onMessage(message: String) {
h.debug("Message received: "+message)
val body: JsValue = Json.parse(message)
try {
if(body.as[JsObject].keys.contains("type")){
val m_type = (body \ "type").as[String]
m_type match {
case "hello" => ;
case "reconnect_url" => setReconnectUrl((body \ "url").as[String])
case "message" => processMessage(body)
case _ => h.debug("Unprocessed message type: " + m_type)
}
}
} catch {
case e: Exception=> e.printStackTrace()
}
}
})
while(slack.isOpen){
}
h.debug("connection is closed")
connect()
}
は、コンソールから出力されます。
Opening Real Time Messaging socket
INFO - Websocket connection open
INFO - Message received: {"type":"hello"}
INFO - Message received: {"reply_to":0,"type":"message","channel":"D1NCSAU12","user":"U1NCSAU0L","text":"pong","ts":"1467558776.000079"}
INFO - Message received: {"type":"reconnect_url","url":"wss://mpmulti-c6k1.slack-msgs.com/websocket/x4UkvMwZeNqFuyZ_YsxjLNi_OIOzqHisL6sHC3DB0QRnKoG-VH8Qr361SlSprlWb6WjzDhw6j5Pj0FiFFYTjoiCLwM-i863os0xWkjUGJJbUoKUmtlG22e3lTTAFuuIFg2TTI7W-0XfU4HJB2nvbjy_hKCwVQ7uIIlrr6fYi_ms="}
INFO - Reconnect URL Set to: wss://mpmulti-c6k1.slack-msgs.com/websocket/x4UkvMwZeNqFuyZ_YsxjLNi_OIOzqHisL6sHC3DB0QRnKoG-VH8Qr361SlSprlWb6WjzDhw6j5Pj0FiFFYTjoiCLwM-i863os0xWkjUGJJbUoKUmtlG22e3lTTAFuuIFg2TTI7W-0XfU4HJB2nvbjy_hKCwVQ7uIIlrr6fYi_ms=
INFO - Message received: {"type":"presence_change","presence":"active","user":"U1NCSAU0L"}
INFO - Unprocessed message type: presence_change
11:23:18.790 [Hashed wheel timer #1] DEBUG com.ning.http.client.providers.netty.channel.pool.DefaultChannelPool - Closed 0 connections out of 0 in 0ms
INFO - Message received: {"type":"user_typing","channel":"D1NCSAU12","user":"U1MP4A19R"}
INFO - Unprocessed message type: user_typing
INFO - Message received: {"type":"message","channel":"D1NCSAU12","user":"U1MP4A19R","text":"ping","ts":"1467559430.000080","team":"T1MQWNFR8"}
INFO - User typed 'ping'
INFO - Answer: {"id":0,"type":"message","channel":"D1NCSAU12","text":"pong"}
INFO - Message received: {"ok":true,"reply_to":0,"ts":"1467559430.000081","text":"pong"}
INFO - Message received: {"type":"user_typing","channel":"D1NCSAU12","user":"U1MP4A19R"}
INFO - Unprocessed message type: user_typing
INFO - Message received: {"type":"message","channel":"D1NCSAU12","user":"U1MP4A19R","text":"ping","ts":"1467559432.000082","team":"T1MQWNFR8"}
INFO - User typed 'ping'
INFO - Answer: {"id":1,"type":"message","channel":"D1NCSAU12","text":"pong"}
INFO - Message received: {"ok":true,"reply_to":1,"ts":"1467559432.000083","text":"pong"}
INFO - Message received: {"type":"user_typing","channel":"D1NCSAU12","user":"U1MP4A19R"}
INFO - Unprocessed message type: user_typing
INFO - Message received: {"type":"message","channel":"D1NCSAU12","user":"U1MP4A19R","text":"ping","ts":"1467559434.000084","team":"T1MQWNFR8"}
INFO - User typed 'ping'
INFO - Answer: {"id":2,"type":"message","channel":"D1NCSAU12","text":"pong"}
INFO - Message received: {"ok":true,"reply_to":2,"ts":"1467559434.000085","text":"pong"}
INFO - Message received: {"type":"user_typing","channel":"D1NCSAU12","user":"U1MP4A19R"}
INFO - Unprocessed message type: user_typing
INFO - Message received: {"type":"message","channel":"D1NCSAU12","user":"U1MP4A19R","text":"ping","ts":"1467559448.000086","team":"T1MQWNFR8"}
INFO - User typed 'ping'
INFO - Answer: {"id":3,"type":"message","channel":"D1NCSAU12","text":"pong"}
INFO - Message received: {"ok":true,"reply_to":3,"ts":"1467559448.000087","text":"pong"}
INFO - Message received: {"type":"user_typing","channel":"D1NCSAU12","user":"U1MP4A19R"}
INFO - Unprocessed message type: user_typing
INFO - Message received: {"type":"message","channel":"D1NCSAU12","user":"U1MP4A19R","text":"ping ping","ts":"1467559452.000088","team":"T1MQWNFR8"}
11:24:18.889 [Hashed wheel timer #1] DEBUG com.ning.http.client.providers.netty.channel.pool.DefaultChannelPool - Closed 0 connections out of 0 in 0ms
INFO - Message received: {"type":"reconnect_url","url":"wss://mpmulti-lbww.slack-msgs.com/websocket/u61Fem7nt3c1DP35C1So6S-Q3QnP0wcY4BeKMG6GZBpjo32E_rGM0YhwH-M_i6uGdezSgzr8R6BmM4eC7ZcwGaAR38GRi2VFyEM7REgtCO0Hd6FAsguHS63TwCI65UwBCkcS_gEFdpoI5tD0az4cBWtdfj1yXbn1iOwpiH_BALg="}
INFO - Reconnect URL Set to: wss://mpmulti-lbww.slack-msgs.com/websocket/u61Fem7nt3c1DP35C1So6S-Q3QnP0wcY4BeKMG6GZBpjo32E_rGM0YhwH-M_i6uGdezSgzr8R6BmM4eC7ZcwGaAR38GRi2VFyEM7REgtCO0Hd6FAsguHS63TwCI65UwBCkcS_gEFdpoI5tD0az4cBWtdfj1yXbn1iOwpiH_BALg=
11:25:18.989 [Hashed wheel timer #1] DEBUG com.ning.http.client.providers.netty.channel.pool.DefaultChannelPool - Closed 0 connections out of 0 in 0ms
INFO - Message received: {}
11:26:13.918 [New I/O worker #1] DEBUG com.ning.http.client.providers.netty.handler.Processor - Channel Closed: [id: 0x0e0d06c0, /192.168.99.102:46345 :> mpmulti-6wbl.slack-msgs.com/54.172.207.190:443] with attribute NettyResponseFuture{currentRetry=5,
isDone=true,
isCancelled=false,
[email protected]ba57,
nettyRe[email protected]b3f8453,
content=NettyWebSocket{channel=[id: 0x0e0d06c0, /192.168.99.102:46345 :> mpmulti-6wbl.slack-msgs.com/54.172.207.190:443]},
uri=wss://mpmulti-6wbl.slack-msgs.com/websocket/0WNxIQsK_mzw561vkxWrN4B3tSPO-oBBR6fPtGnD2GLP_47Cms8s8GzyNl8ujheXVnNIw0RygTwglxlZYdfChlNf_0MfCwihOeQMUI-hjgCcwxXuMZFUSYrZphQpu1w7VYP5j3dc0nOVnL0YZX_oi62cgeoaWgwn5GjUiif-0AM=,
keepAlive=true,
ht[email protected]790add3d,
exEx=null,
redirectCount=0,
timeoutsHolder=null,
inAuth=false,
statusReceived=false,
touch=530188604}
INFO - Websocket connection closed, reconnecting...
11:26:13.920 [New I/O worker #1] DEBUG com.ning.http.client.providers.netty.channel.ChannelManager - Closing Channel [id: 0x0e0d06c0, /192.168.99.102:46345 :> mpmulti-6wbl.slack-msgs.com/54.172.207.190:443]
どのようにpingを送信しましたか? – dopatraman
「Ping and Pong」セクションのRTMドキュメント(https://api.slack.com/rtm)を参照してください。このメッセージは定期的に送信する必要があります。このメッセージは他のメッセージと同様に送信されます。 – autronix
が優れています。なぜ私のクライアントが無作為に動作しなくなったのか理解しようとしていました。 +1。 – dopatraman