Skip to main content

Set Up a Match Notification

Last updated on

This function sends a notification to the player when they successfully find a match.

// GO-SDK lobby service
func sendNotificationFound(
namespace,
IP string,
port int32,
allUsers []string) (bool, error) {
topic := constants.MatchmakingNotificationTopic
gameNotificationService := lobby.NotificationService{
Client: factory.NewLobbyClient(&configImpl),
TokenRepository: &tokenRepositoryImpl,
}
messageIPPort := fmt.Sprintf("found %v %v", IP, port)
body := lobbyclientmodels.ModelFreeFormNotificationRequest{
Message: &messageIPPort,
Topic: &topic,
}
for _, userIdToSend := range allUsers {
input := &notification.FreeFormNotificationByUserIDParams{
Body: &body,
Namespace: namespace,
UserID: userIdToSend,
}
sendNotificationMatchFoundErr := gameNotificationService.FreeFormNotificationByUserID(input)
if sendNotificationMatchFoundErr != nil {
log.Print(sendNotificationMatchFoundErr)
return false, sendNotificationMatchFoundErr
}
log.Printf("Match found! Successfully send notification to userId : %+v", userIdToSend)
}

return true, nil
}