Skip to content

Commit 9065743

Browse files
Yashwanth1906ompandey21manujohnson1234
authored andcommitted
fix : xyne thread id correction
* fix : xyne thread id correction * ench: overlayNotification data in grpc --------- Co-authored-by: Om Dutt Pandey <omdutt2004@gmail.com> Co-authored-by: manu johnson <manujohnson2002@gmail.com>
1 parent 35777c7 commit 9065743

5 files changed

Lines changed: 108 additions & 17 deletions

File tree

lib/mobility-core/src/Kernel/External/Notification/Interface.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ notifyPersonWithAllProviders ::
6868
MonadReader r m,
6969
HasFlowEnv m r '["maxNotificationShards" ::: Int]
7070
) =>
71-
NotficationServiceHandler m a c ->
71+
NotficationServiceHandler m c ->
7272
NotificationReq a b ->
7373
Maybe LiveActivityReq ->
7474
m () ->

lib/mobility-core/src/Kernel/External/Notification/Interface/FCM.hs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Kernel.External.Notification.Interface.FCM where
22

3+
import Data.Aeson (Value (..), object, (.=))
34
import qualified Kernel.External.Notification.FCM.Flow as FCM
45
import qualified Kernel.External.Notification.FCM.Types as FCM
56
import qualified Kernel.External.Notification.Interface.Types as Interface
@@ -24,7 +25,7 @@ notifyPerson ::
2425
Maybe FCM.LiveActivityReq ->
2526
m () ->
2627
Maybe Text ->
27-
(FCM.FCMData a -> FCM.FCMData c) ->
28+
(FCM.FCMData Value -> FCM.FCMData c) ->
2829
m ()
2930
notifyPerson config req liveAcitvityRequest action mbNotificationId iosModifier = do
3031
let title = FCM.FCMNotificationTitle req.title
@@ -36,9 +37,9 @@ notifyPerson config req liveAcitvityRequest action mbNotificationId iosModifier
3637
fcmShowNotification = interfaceShowNotificationToFCMShowNotification req.showNotification,
3738
fcmEntityType = interfaceEntityTypeToFCMEntityType req.entity.entityType,
3839
fcmEntityIds = req.entity.entityIds,
39-
fcmEntityData = req.entity.entityData,
40+
fcmEntityData = mergeEntityWithOverlay (toJSON req.entity.entityData) req.overlayNotificationData,
4041
fcmNotificationJSON = FCM.createAndroidNotification title body notificationType req.sound,
41-
fcmOverlayNotificationJSON = Nothing,
42+
fcmOverlayNotificationJSON = overlayNotificationDataToFCM <$> req.overlayNotificationData,
4243
fcmNotificationId = mbNotificationId
4344
}
4445
apnsData = liveAcitvityRequest
@@ -53,6 +54,43 @@ notifyPerson config req liveAcitvityRequest action mbNotificationId iosModifier
5354
(FCM.FCMNotificationRecipient req.auth.recipientId (FCM.FCMRecipientToken <$> req.auth.fcmToken))
5455
iosModifier
5556

57+
overlayNotificationDataToFCM :: Interface.OverlayNotificationData -> FCM.FCMOverlayNotificationJSON
58+
overlayNotificationDataToFCM d =
59+
FCM.FCMOverlayNotificationJSON
60+
{ title = d.title,
61+
description = d.description,
62+
imageUrl = d.imageUrl,
63+
okButtonText = d.okButtonText,
64+
cancelButtonText = d.cancelButtonText,
65+
actions = d.actions,
66+
actions2 = d.actions2,
67+
secondaryActions2 = d.secondaryActions2,
68+
link = d.link,
69+
endPoint = d.endPoint,
70+
method = d.method,
71+
reqBody = d.reqBody,
72+
titleVisibility = d.titleVisibility,
73+
descriptionVisibility = d.descriptionVisibility,
74+
buttonOkVisibility = d.buttonOkVisibility,
75+
buttonCancelVisibility = d.buttonCancelVisibility,
76+
buttonLayoutVisibility = d.buttonLayoutVisibility,
77+
imageVisibility = d.imageVisibility,
78+
delay = d.delay,
79+
contactSupportNumber = d.contactSupportNumber,
80+
toastMessage = d.toastMessage,
81+
secondaryActions = d.secondaryActions,
82+
socialMediaLinks = d.socialMediaLinks,
83+
showPushNotification = d.showPushNotification
84+
}
85+
86+
mergeEntityWithOverlay :: Value -> Maybe Interface.OverlayNotificationData -> Value
87+
mergeEntityWithOverlay entityJson Nothing = entityJson
88+
mergeEntityWithOverlay entityJson (Just overlay) =
89+
let overlayObj = object ["driver_notification_payload" .= toJSON overlay]
90+
in case (entityJson, overlayObj) of
91+
(Object eo, Object oo) -> Object (eo <> oo)
92+
_ -> entityJson
93+
5694
interfaceMessagePriorityToFCMMessagePriority :: Interface.MessagePriority -> FCM.FCMAndroidMessagePriority
5795
interfaceMessagePriorityToFCMMessagePriority = \case
5896
Interface.NORMAL -> FCM.NORMAL

lib/mobility-core/src/Kernel/External/Notification/Interface/GRPC.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
module Kernel.External.Notification.Interface.GRPC where
1616

17+
import Data.Aeson (Value (..), object, (.=))
1718
import EulerHS.Prelude
1819
import qualified Kernel.External.Notification.GRPC.Flow as GRPC
1920
import qualified Kernel.External.Notification.GRPC.Types as GRPC
@@ -39,15 +40,26 @@ notifyPerson config req notificationId = do
3940
let title = GRPC.GRPCNotificationTitle req.title
4041
body = GRPC.GRPCNotificationBody req.body
4142
notificationType = show req.category
43+
entityDataJson = mergeEntityWithOverlay (toJSON req.entity.entityData) req.overlayNotificationData
4244
notificationData =
4345
GRPC.GrpcNotificationData
4446
{ entityId = req.entity.entityIds,
4547
entityType = show req.entity.entityType,
46-
entityData = req.entity.entityData,
48+
entityData = entityDataJson,
4749
category = notificationType,
4850
showNotification = show req.showNotification,
4951
ttl = fromMaybe defaultTtlTime req.ttl,
5052
streamId = req.auth.recipientId,
5153
..
5254
}
5355
GRPC.notifyPerson config notificationData
56+
57+
-- | Embed overlay data as \"driver_notification_payload\" inside the entity
58+
-- data JSON so GRPC consumers read it the same way as FCM consumers do.
59+
mergeEntityWithOverlay :: Value -> Maybe Interface.OverlayNotificationData -> Value
60+
mergeEntityWithOverlay entityJson Nothing = entityJson
61+
mergeEntityWithOverlay entityJson (Just overlay) =
62+
let overlayObj = object ["driver_notification_payload" .= toJSON overlay]
63+
in case (entityJson, overlayObj) of
64+
(Object eo, Object oo) -> Object (eo <> oo)
65+
_ -> entityJson

lib/mobility-core/src/Kernel/External/Notification/Interface/Types.hs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
module Kernel.External.Notification.Interface.Types where
1919

20+
import Data.Aeson (Value)
2021
import Kernel.Beam.Lib.UtilsTH (mkBeamInstancesForEnum)
2122
import Kernel.External.Notification.FCM.Types
2223
import qualified Kernel.External.Notification.FCM.Types as FCM
@@ -177,6 +178,34 @@ data Entity a = Entity
177178
}
178179
deriving (Show, Eq, Read, Generic, ToJSON, FromJSON)
179180

181+
data OverlayNotificationData = OverlayNotificationData
182+
{ title :: Maybe Text,
183+
description :: Maybe Text,
184+
imageUrl :: Maybe Text,
185+
okButtonText :: Maybe Text,
186+
cancelButtonText :: Maybe Text,
187+
actions :: [Text],
188+
actions2 :: [FCMActions],
189+
secondaryActions2 :: Maybe [FCMActions],
190+
link :: Maybe Text,
191+
endPoint :: Maybe Text,
192+
method :: Maybe Text,
193+
reqBody :: Value,
194+
titleVisibility :: Bool,
195+
descriptionVisibility :: Bool,
196+
buttonOkVisibility :: Bool,
197+
buttonCancelVisibility :: Bool,
198+
buttonLayoutVisibility :: Bool,
199+
imageVisibility :: Bool,
200+
delay :: Maybe Int,
201+
contactSupportNumber :: Maybe Text,
202+
toastMessage :: Maybe Text,
203+
secondaryActions :: Maybe [Text],
204+
socialMediaLinks :: Maybe [FCMMediaLink],
205+
showPushNotification :: Maybe Bool
206+
}
207+
deriving (Eq, Show, Generic, ToJSON, FromJSON)
208+
180209
data NotificationReq a b = NotificationReq
181210
{ auth :: Auth,
182211
category :: Category,
@@ -188,12 +217,13 @@ data NotificationReq a b = NotificationReq
188217
body :: Text,
189218
title :: Text,
190219
ttl :: Maybe UTCTime,
191-
sound :: Maybe Text
220+
sound :: Maybe Text,
221+
overlayNotificationData :: Maybe OverlayNotificationData
192222
}
193-
deriving (Show, Eq, Read, Generic, ToJSON, FromJSON)
223+
deriving (Show, Eq, Generic, ToJSON, FromJSON)
194224

195-
data NotficationServiceHandler m a b = NotficationServiceHandler
225+
data NotficationServiceHandler m b = NotficationServiceHandler
196226
{ getNotificationServiceList :: m [Interface.NotificationService],
197227
getServiceConfig :: Interface.NotificationService -> m NotificationServiceConfig,
198-
iosModifier :: FCMData a -> FCMData b
228+
iosModifier :: FCMData Value -> FCMData b
199229
}

lib/mobility-core/src/Kernel/External/Ticket/Interface/XyneSpaces.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
-- @rideDescription@ (preferring customer over driver). Email is left
3434
-- @Nothing@ for now — 'IssueManagement.Common.Person' has no email field.
3535
--
36-
-- Note on the returned @ticketId@: we echo back the threadId (= IssueReport id)
37-
-- rather than Xyne's opaque ticketId so that the existing IssueManagement
38-
-- caller can pass it back unchanged on subsequent updateTicket calls. Xyne's
39-
-- own ticketId / xyneId / conversationId are logged but not propagated.
36+
-- Note on the returned @ticketId@: both 'createTicket' and 'updateTicket'
37+
-- return Xyne's own opaque ticketId (from the @appDeskInbound@ response),
38+
-- not our @threadId@ (= IssueReport id). The threadId is still required on
39+
-- every @appDeskInbound@ call to keep appending to the same Xyne thread, so
40+
-- callers must keep passing it separately via @req.issueDetails.issueId@ on
41+
-- 'updateTicket' (see 'IT.UpdateTicketReq'); the opaque ticketId travels via
42+
-- @req.ticketId@ / @IssueReport.ticketId@ as with the other providers.
4043
module Kernel.External.Ticket.Interface.XyneSpaces
4144
( createTicket,
4245
updateTicket,
@@ -117,7 +120,7 @@ createTicket config req = do
117120
<> show resp.isNew
118121
pure
119122
IT.CreateTicketResp
120-
{ ticketId = threadId,
123+
{ ticketId = resp.ticketId,
121124
status = IT.Open,
122125
requesterId = Nothing
123126
}
@@ -132,8 +135,14 @@ updateTicket ::
132135
IT.UpdateTicketReq ->
133136
m IT.UpdateTicketResp
134137
updateTicket config req = do
135-
-- req.ticketId is the value createTicket returned (= our threadId).
136-
let threadId = req.ticketId
138+
-- req.ticketId is now Xyne's opaque ticketId (see the module-level note),
139+
-- not our threadId, so it cannot be used to correlate the appDeskInbound
140+
-- call to the existing thread. The threadId (= IssueReport id) must come
141+
-- from req.issueDetails.issueId, which callers are expected to keep
142+
-- populated across the create/update lifecycle.
143+
threadId <- case req.issueDetails >>= (.issueId) of
144+
Just t -> pure t
145+
Nothing -> throwError (InternalError "Xyne updateTicket requires issueDetails.issueId (used as threadId)")
137146
token <- decrypt config.token
138147
let (mbRideName, _) = senderInfoFromRide req.rideDescription
139148
mbSenderName = req.name <|> mbRideName
@@ -161,9 +170,11 @@ updateTicket config req = do
161170
<> " isNew="
162171
<> show resp.isNew
163172
-- Mirror Zendesk: return req.status (caller intent), not the parsed response.
173+
-- ticketId echoes back Xyne's opaque id (resp.ticketId), consistent with
174+
-- createTicket and with how Kapture/Zendesk report their own ticket id.
164175
pure
165176
IT.UpdateTicketResp
166-
{ ticketId = threadId,
177+
{ ticketId = resp.ticketId,
167178
status = req.status,
168179
message = "Ticket updated"
169180
}

0 commit comments

Comments
 (0)