fayec/examples/groupme.go

43 lines
936 B
Go
Raw Normal View History

2023-09-19 01:58:15 +00:00
package main
import (
"fmt"
2023-09-19 02:01:38 +00:00
"gitea.watsonlabs.net/watsonb8/fayec"
"gitea.watsonlabs.net/watsonb8/fayec/message"
"gitea.watsonlabs.net/watsonb8/fayec/subscription"
2023-09-19 01:58:15 +00:00
"time"
)
var authorizationToken = "ABC"
var authenticationExtension message.Extension = func(message *message.Message) {
if message.Channel == "/meta/subscribe" {
message.Ext = map[string]string{
"access_token": authorizationToken,
"timestamp": string(time.Now().Unix()),
}
}
}
func main() {
client, err := fayec.NewClient("wss://push.groupme.com/faye", fayec.WithOutExtension(authenticationExtension))
defer client.Disconnect()
if err != nil {
fmt.Errorf("Error connecting to groupme", err)
return
}
var sub *subscription.Subscription
sub, err = client.Subscribe("/user/13685836")
if err != nil {
panic(err)
}
err = sub.OnMessage(func(channel string, data message.Data) {
fmt.Println(data)
})
if err != nil {
panic(err)
}
}