abhinavdahiya / go-messenger-bot

Golang bindings for the Messenger Bot API
https://godoc.org/github.com/abhinavdahiya/go-messenger-bot
MIT License
52 stars 10 forks source link

Goroutine use for listen #2

Closed alanef closed 8 years ago

alanef commented 8 years ago

Hi

Is there any reason in your example code you are using a goroutine for the listen?

go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", mux)

I have only ever seen using goroutines like this when one program has to listen on multiple ports.

Interest to see why you chose to do this this way?

Alan

abhinavdahiya commented 8 years ago

Hi @alanef

As you know http.ListenAndServeTLS is an blocking operation ie program halts here to listen and no instructions after that will be run and setwebhook also returns a channel where you can listen for callbacks received check here

I chose the example program to have handling the content of callback channel as main focus coz thats the main aim of the program right! :) , and use a separate goroutine to serve as listener (http.ListenAndServeTLS).

Its just a personal choice to emphasize on the main aim of this library ie to handle the callbacks

alanef commented 8 years ago

Many thanks for taking the time to explain.

I have only been working with Golang for a short while. I have learned a lot reading through your code.

By the way, I how have my test bot working perfectly with your routines, for text, buttons and cards.

Now on to my next task, working out how to call wit.ai effectively from my bot :)

alanef commented 8 years ago

p.s. the only 'gotcha' I came across (due to lack of fully understanding the FB environment) was on send of cards or butons it is important to set notif to SilentNotif, otherwise I got a loop.