Skip to content

Commit

Permalink
fix: unmarshall payload to avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Doozers committed Aug 9, 2022
1 parent 672898b commit 8090887
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 1 addition & 7 deletions go/pkg/bertybot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ func (b *Bot) handleEvent(ctx context.Context, event *messengertypes.StreamEvent
}
b.callHandlers(context, UserMessageHandler)
case messengertypes.AppMessage_TypeGroupInvitation:
context.ReplyString("I'll join asasp !")

invLink := context.EventPayload.(*messengertypes.AppMessage_GroupInvitation).Link

req := messengertypes.ConversationJoin_Request{Link: invLink}
ctx.Client.ConversationJoin(ctx.Context, &req)

b.callHandlers(context, IncomingGroupInvitationHandler)
default:
return fmt.Errorf("unsupported interaction type: %q", context.Interaction.Type)
}
Expand Down
14 changes: 9 additions & 5 deletions go/pkg/bertybot/recipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,21 @@ func DelayResponseRecipe(duration time.Duration) Recipe {
return recipe
}

// AutoAcceptIncomingContactRequestRecipe makes the bot "click" on the "accept" button automatically.
// AutoAcceptIncomingGroupInviteRecipe makes the bot "click" on the "join" button automatically.
func AutoAcceptIncomingGroupInviteRecipe() Recipe {
recipe := map[HandlerType][]Handler{}
recipe[IncomingGroupInvitationHandler] = []Handler{
func(ctx Context) {
ctx.ReplyString("I'll join asasp !")
func(context Context) {
context.ReplyString("I'll join asasp !")

invLink := ctx.EventPayload.(*messengertypes.AppMessage_GroupInvitation).Link
payload, err := context.Interaction.UnmarshalPayload()
if err != nil {
return
}
invLink := payload.(*messengertypes.AppMessage_GroupInvitation).Link

req := messengertypes.ConversationJoin_Request{Link: invLink}
ctx.Client.ConversationJoin(ctx.Context, &req)
context.Client.ConversationJoin(context.Context, &req)
},
}
return recipe
Expand Down

0 comments on commit 8090887

Please sign in to comment.