Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubscribeToMessageStream need help to understand #32

Closed
tbellembois opened this issue Apr 19, 2019 · 1 comment
Closed

SubscribeToMessageStream need help to understand #32

tbellembois opened this issue Apr 19, 2019 · 1 comment

Comments

@tbellembois
Copy link

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.

	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.

Thanks for your help.

@tbellembois
Copy link
Author

Did not see pull request #21 sorry.
This fixes my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant