-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(framework): Add new Inbox properties to
step.inApp
schema (#6075)
Co-authored-by: Joel Anton <[email protected]>
- Loading branch information
Showing
12 changed files
with
149 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,70 @@ | ||
import { WorkflowTypeEnum } from '../types'; | ||
import { ButtonTypeEnum, IMessage, IMessageCTA } from '../entities/messages'; | ||
import { ChannelCTATypeEnum, WorkflowTypeEnum } from '../types'; | ||
|
||
export const isBridgeWorkflow = (workflowType?: WorkflowTypeEnum): boolean => { | ||
return workflowType === WorkflowTypeEnum.BRIDGE || workflowType === WorkflowTypeEnum.ECHO; | ||
}; | ||
|
||
/** | ||
* This typing already lives in @novu/framework, but due to a circular dependency, we currently | ||
* need to duplicate it here. | ||
* | ||
* TODO: reconsider the dependency tree between @novu/shared and @novu/framework and move this | ||
* function to be shared across all apps. We will likely want to create a separate package for | ||
* schemas and their inferred type definitions. | ||
*/ | ||
type InAppOutput = { | ||
subject?: string; | ||
body: string; | ||
avatar?: string; | ||
primaryAction?: { | ||
label: string; | ||
url?: string; | ||
}; | ||
secondaryAction?: { | ||
label: string; | ||
url?: string; | ||
}; | ||
}; | ||
|
||
type InAppMessage = Pick<IMessage, 'subject' | 'content' | 'cta' | 'avatar'>; | ||
|
||
/** | ||
* This function maps the V2 InAppOutput to the V1 MessageEntity. | ||
*/ | ||
export const inAppMessageFromBridgeOutputs = (outputs?: InAppOutput) => { | ||
const cta = { | ||
type: ChannelCTATypeEnum.REDIRECT, | ||
data: {}, | ||
action: { | ||
result: {}, | ||
buttons: [ | ||
...(outputs?.primaryAction | ||
? [ | ||
{ | ||
type: ButtonTypeEnum.PRIMARY, | ||
content: outputs.primaryAction.label, | ||
url: outputs.primaryAction.url, | ||
}, | ||
] | ||
: []), | ||
...(outputs?.secondaryAction | ||
? [ | ||
{ | ||
type: ButtonTypeEnum.SECONDARY, | ||
content: outputs.secondaryAction.label, | ||
url: outputs.secondaryAction.url, | ||
}, | ||
] | ||
: []), | ||
], | ||
}, | ||
} satisfies IMessageCTA; | ||
|
||
return { | ||
subject: outputs?.subject, | ||
content: outputs?.body || '', | ||
cta, | ||
avatar: outputs?.avatar, | ||
} satisfies InAppMessage; | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/framework/src/schemas/steps/channels/in-app.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters