@@ -18,6 +18,7 @@ package connector
1818
1919import (
2020 "context"
21+ "encoding/json"
2122 "fmt"
2223 "sync"
2324 "sync/atomic"
@@ -97,28 +98,40 @@ type WhatsAppClient struct {
9798 lastPhoneOfflineWarning time.Time
9899}
99100
100- var _ bridgev2.NetworkAPI = (* WhatsAppClient )(nil )
101+ var (
102+ _ bridgev2.NetworkAPI = (* WhatsAppClient )(nil )
103+ _ bridgev2.PushableNetworkAPI = (* WhatsAppClient )(nil )
104+ )
101105
102106var pushCfg = & bridgev2.PushConfig {
103- Web : & bridgev2.WebPushConfig {},
107+ // TODO web push config might have to be fetched from server
108+ //Web: &bridgev2.WebPushConfig{},
109+ FCM : & bridgev2.FCMPushConfig {SenderID : "293955441834" },
104110}
105111
106112func (wa * WhatsAppClient ) GetPushConfigs () * bridgev2.PushConfig {
107- // implement get application server key (to be added to whatsmeow)
108- //pushCfg.Web.VapidKey = applicationServerKey
109113 return pushCfg
110114}
111115
112- func (wa * WhatsAppClient ) RegisterPushNotifications (_ context.Context , pushType bridgev2.PushType , _ string ) error {
116+ func (wa * WhatsAppClient ) RegisterPushNotifications (ctx context.Context , pushType bridgev2.PushType , token string ) error {
113117 if wa .Client == nil {
114118 return bridgev2 .ErrNotLoggedIn
115119 }
116- if pushType != bridgev2 .PushTypeWeb {
117- return fmt .Errorf ("unsupported push type: %s" , pushType )
120+ var pc whatsmeow.PushConfig
121+ switch pushType {
122+ case bridgev2 .PushTypeFCM :
123+ pc = & whatsmeow.FCMPushConfig {Token : token }
124+ case bridgev2 .PushTypeWeb :
125+ var webPC whatsmeow.WebPushConfig
126+ err := json .Unmarshal ([]byte (token ), & webPC )
127+ if err != nil {
128+ return err
129+ }
130+ pc = & webPC
131+ default :
132+ return fmt .Errorf ("unsupported push type %s" , pushType )
118133 }
119-
120- //wa.Client.RegisterWebPush(ctx, token) (to be added to whatsmeow)
121- return nil
134+ return wa .Client .RegisterForPushNotifications (ctx , pc )
122135}
123136
124137func (wa * WhatsAppClient ) IsThisUser (_ context.Context , userID networkid.UserID ) bool {
0 commit comments