I try to develop a real time light bot for Rocket.
My bot subscribe to each direct room (ie. conversation with other users) with a common channel.
if channels, e = c.GetChannelsIn(); e != nil {
log.Panic("can not get channels in " + e.Error())
}
msgChannel := make(chan models.Message, 10)
for _, ch := range channels {
fmt.Println(fmt.Printf("subscribed to: %v", ch.ID))
if e = c.SubscribeToMessageStream(&models.Channel{ID: ch.ID}, msgChannel); e != nil {
log.Println("can not subscribe to message stream for channel " + ch.ID + " " + e.Error())
}
}
count := 0
for {
fmt.Println(count)
select {
case m := <-msgChannel:
fmt.Println(fmt.Sprintf("ID: %s RoomID: %s Msg: %s User: %v", m.ID, m.RoomID, m.Msg, m.User))
count++
}
}
When I send a direct message to the bot on the Rocket Chat application the for loop prints exactly [number of subscribed channels] times the log message.
It can not figure out why. I just wanted to wait for messages in the channel and reply to the sender.
Hi,
I try to develop a real time light bot for Rocket. My bot subscribe to each direct room (ie. conversation with other users) with a common channel.
When I send a direct message to the bot on the Rocket Chat application the
for
loop prints exactly [number of subscribed channels] times the log message. It can not figure out why. I just wanted to wait for messages in the channel and reply to the sender.Thanks for your help.