Skip to content

Commit e662384

Browse files
committed
refactor: Add Back-end url to Slack and Email Action
1 parent 4098806 commit e662384

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

src/modules/mpn-automation/services/slack-action-service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ export class SlackActionService extends BaseActionService {
4646

4747
const { blocks } = await slackService.render({
4848
templateName: params.templateName,
49-
data: {
50-
...transformedContext,
51-
backend_url: params.options?.backendUrl,
52-
},
49+
data: transformedContext,
5350
options: params.options
5451
})
5552

src/subscribers/inventory-level-updated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "@medusajs/medusa"
55
import { getInventoryLevelByIdWorkflow } from "../workflows/inventory/get-inventory-level-by-id"
66
import { runAutomationWorkflow } from "../workflows/mpn-automation/run-automation"
7+
import { getPluginOptions } from "../utils/plugins"
78
import { TriggerType } from "../utils/types"
89

910
const eventName = "inventory.inventory-level.updated"

src/subscribers/mpn.automation.action.email.executed.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type SubscriberConfig,
44
} from "@medusajs/medusa"
55
import { runEmailActionWorkflow } from "../workflows/mpn-automation/run-email-action"
6+
import { getPluginOptions } from "../utils/plugins"
67

78
/**
89
* Event name for the MPN automation action email executed event.
@@ -28,6 +29,15 @@ export default async function mpnAutomationActionEmailExecutedHandler({
2829
eventName: triggerEventName,
2930
contextType,
3031
} = data
32+
const pluginOptions = getPluginOptions(container, "@codee-sh/medusa-plugin-notification-emails")
33+
const backendUrl = pluginOptions?.backend_url
34+
35+
const contextData = {
36+
...context,
37+
global: {
38+
backend_url: backendUrl,
39+
},
40+
}
3141

3242
const { result } = await runEmailActionWorkflow(
3343
container
@@ -45,7 +55,7 @@ export default async function mpnAutomationActionEmailExecutedHandler({
4555
"inventory-level",
4656
},
4757
},
48-
context: context,
58+
context: contextData,
4959
contextType: contextType,
5060
eventName: triggerEventName,
5161
},

src/subscribers/mpn.automation.action.slack.executed.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type SubscriberConfig,
44
} from "@medusajs/medusa"
55
import { runSlackActionWorkflow } from "../workflows/mpn-automation/run-slack-action"
6+
import { getPluginOptions } from "../utils/plugins"
67

78
/**
89
* Event name for the MPN automation action slack executed event.
@@ -28,9 +29,19 @@ export default async function mpnAutomationActionSlackExecutedHandler({
2829
eventName: triggerEventName,
2930
contextType,
3031
} = data
31-
const config = container.resolve("configModule") as any
32-
const moduleConfig = config?.modules.mpnAutomation
33-
const backendUrl = moduleConfig?.options.backend_url
32+
const pluginOptions = getPluginOptions(container, "@codee-sh/medusa-plugin-notification-emails")
33+
const backendUrl = pluginOptions?.backend_url
34+
35+
// const config = container.resolve("configModule") as any
36+
// const moduleConfig = config?.modules.mpnAutomation
37+
// const backendUrl = moduleConfig?.options.backend_url
38+
39+
const contextData = {
40+
...context,
41+
global: {
42+
backend_url: backendUrl,
43+
},
44+
}
3445

3546
// Execute slack action workflow
3647
const { result } = await runSlackActionWorkflow(
@@ -41,11 +52,10 @@ export default async function mpnAutomationActionSlackExecutedHandler({
4152
...action,
4253
config: {
4354
...action.config,
44-
template: action.config.templateName,
45-
backendUrl: backendUrl,
55+
template: action.config.templateName
4656
},
4757
},
48-
context: context,
58+
context: contextData,
4959
contextType: contextType,
5060
eventName: triggerEventName,
5161
},

0 commit comments

Comments
 (0)