Handlers are now fired for individual users
This commit is contained in:
@ -11,7 +11,8 @@ import (
|
||||
// This is not a real token. Please find yours by logging
|
||||
// into the GroupMe development website: https://dev.groupme.com/
|
||||
|
||||
var authorizationToken = "ABCD"
|
||||
var authorizationToken = "ASD"
|
||||
var authorizationToken2 = "ASDF"
|
||||
|
||||
// A short program that subscribes to 2 groups and 2 direct chats
|
||||
// and prints out all recognized events in those
|
||||
@ -26,12 +27,15 @@ func main() {
|
||||
// Create a new client with your auth token
|
||||
client := groupme.NewClient()
|
||||
User, _ := client.MyUser(context.Background(), authorizationToken)
|
||||
User2, _ := client.MyUser(context.Background(), authorizationToken2)
|
||||
|
||||
//handles (in this case prints) all messages
|
||||
p.AddFullHandler(Handler{User: User})
|
||||
p.AddFullHandler(Handler{User: User}, authorizationToken)
|
||||
p.AddHandler(Handler{User: User2}, authorizationToken2)
|
||||
|
||||
//Subscribe to get messages and events for the specific user
|
||||
err = p.SubscribeToUser(context.Background(), User.ID, authorizationToken)
|
||||
p.SubscribeToUser(context.Background(), User.ID, authorizationToken)
|
||||
p.SubscribeToUser(context.Background(), User2.ID, authorizationToken2)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -45,6 +49,14 @@ func main() {
|
||||
Omit: "memberships",
|
||||
}, authorizationToken)
|
||||
|
||||
groups2, err := client.IndexGroups(
|
||||
context.Background(),
|
||||
&groupme.GroupsQuery{
|
||||
Page: 0,
|
||||
PerPage: 2,
|
||||
Omit: "memberships",
|
||||
}, authorizationToken2)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@ -57,18 +69,43 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
for _, j := range groups2 {
|
||||
err = p.SubscribeToGroup(context.TODO(), j.ID, authorizationToken2)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//get chats your user is part of
|
||||
chats, err := client.IndexChats(context.Background(),
|
||||
&groupme.IndexChatsQuery{
|
||||
Page: 0,
|
||||
PerPage: 2,
|
||||
}, authorizationToken)
|
||||
chats2, err := client.IndexChats(context.Background(),
|
||||
&groupme.IndexChatsQuery{
|
||||
Page: 0,
|
||||
PerPage: 2,
|
||||
}, authorizationToken2)
|
||||
//subscribe to all those chats
|
||||
for _, j := range chats {
|
||||
err = p.SubscribeToDM(context.TODO(), j.LastMessage.ConversationID, authorizationToken)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
err := p.SubscribeToDM(context.TODO(), j.LastMessage.ConversationID, authorizationToken)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
for _, j := range chats2 {
|
||||
go func() {
|
||||
err := p.SubscribeToDM(context.TODO(), j.LastMessage.ConversationID, authorizationToken2)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
//blocking
|
||||
|
Reference in New Issue
Block a user