diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 49708eb7a..a740c2c66 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -44,7 +44,7 @@ "@tradle/bot-products": { "version": "1.0.0", "from": "tradle/bot-products", - "resolved": "git://github.com/tradle/bot-products.git#ff2979fdba50493a5508efa428ec70e9137bf1ab", + "resolved": "git://github.com/tradle/bot-products.git#54f4a1cce93cb68b8bcb9275d36255c1dde29c23", "dependencies": { "debug": { "version": "3.1.0", diff --git a/src/in-house-bot/index.ts b/src/in-house-bot/index.ts index b362630a5..70b9c2a1d 100644 --- a/src/in-house-bot/index.ts +++ b/src/in-house-bot/index.ts @@ -330,6 +330,11 @@ export default function createProductsBot ({ productsAPI.plugins.use(setNamePlugin({ bot, productsAPI })) productsAPI.plugins.use({ onmessage: async (req) => { + if (req.application && req.application.draft) { + req.skipChecks = true + } + }, + ['onmessage:tradle.ProductRequest']: async (req) => { const { application } = req if (!application) return @@ -338,19 +343,14 @@ export default function createProductsBot ({ req.isFromEmployee = employeeManager.isEmployee(req.user) if (!req.isFromEmployee) return - if (req.type === 'tradle.ProductRequest') { - logger.debug('setting application.draft, as this is an employee applying on behalf of a customer') - application.draft = true - await productsAPI.sendSimpleMessage({ - req, - to: req.user, - message: `Note: this is a draft application. When you finish you will be given a set of links that can be used to import` - }) - } - - if (application.draft) { - req.skipChecks = true - } + logger.debug('setting application.draft, as this is an employee applying on behalf of a customer') + application.draft = true + req.skipChecks = true + await productsAPI.sendSimpleMessage({ + req, + to: req.user, + message: `Note: this is a draft application. When you finish you will be given a set of links that can be used to import` + }) } }) diff --git a/src/in-house-bot/plugins/remediation.ts b/src/in-house-bot/plugins/remediation.ts index 7a8b5c0c3..086f07641 100644 --- a/src/in-house-bot/plugins/remediation.ts +++ b/src/in-house-bot/plugins/remediation.ts @@ -1,5 +1,12 @@ import { TYPES } from '../constants' -import { IPluginOpts, IPluginExports, IPluginLifecycleMethods, IPBReq } from '../types' +import { + IPluginOpts, + IPluginExports, + IPluginLifecycleMethods, + IPBReq, + IUser, + IPBApp +} from '../types' import { Remediation } from '../remediation' import { appLinks } from '../../app-links' const { DATA_CLAIM, PRODUCT_REQUEST } = TYPES @@ -21,9 +28,13 @@ export const createPlugin = (opts:IPluginOpts):IRemediationPluginExports => { }) } - plugin[`onmessage:${PRODUCT_REQUEST}`] = async ({ user, application, payload }: IPBReq) => { - const claimId = payload.contextId - if (application && remediation.isPrefillClaimId(claimId)) { + plugin.willCreateApplication = async ({ req, user, application }: { + req: IPBReq + user: IUser + application: IPBApp + }) => { + const claimId = req.payload.contextId + if (remediation.isPrefillClaimId(claimId)) { try { await remediation.handlePrefillClaim({ user, application, claimId }) } catch (err) { @@ -41,7 +52,7 @@ export const createPlugin = (opts:IPluginOpts):IRemediationPluginExports => { claimType: 'prefill' }) - const [mobile, web] = ['mobile', 'web'].map(platform => appLinks.getApplyForProductLink({ + const [mobile, web] = ['mobile', 'web'].map(platform => bot.appLinks.getApplyForProductLink({ provider, host: bot.apiBaseUrl, product: application.requestFor,