-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0930a0f
Showing
8 changed files
with
184 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
parameters: './parameters.yml', | ||
workflows_directory: './workflows/', | ||
jobs_directory: './jobs/', | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const replyService = require('../services/service'); | ||
|
||
module.exports = async(job) => { | ||
|
||
const { | ||
body, | ||
workflow: { | ||
data: wfData | ||
} | ||
} = job.data; | ||
|
||
try { | ||
await replyService.api(wfData.api_key).send('GET', `/v1/people?email=${encodeURIComponent(body.email)}`); | ||
job.progress(35); | ||
|
||
await replyService.api(wfData.api_key).send('POST', '/v1/actions/removepersonfromallcampaigns', { | ||
'email': body.email | ||
}); | ||
job.progress(75); | ||
|
||
await replyService.api(wfData.api_key).send('POST', '/v1/actions/pushtocampaign', { | ||
'campaignId': wfData.campaign_id, | ||
'email': body.email, | ||
}); | ||
job.progress(100); | ||
|
||
} catch(err) { | ||
if(err.statusCode === 404) { | ||
await replyService.api(wfData.api_key).send('POST', '/v1/actions/addandpushtocampaign', { | ||
'campaignId': wfData.campaign_id, | ||
'email': body.email, | ||
'firstName': body.email, | ||
}); | ||
job.progress(100); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "workflow-lib/reply", | ||
"version": "0.0.1", | ||
"description": "Reply jobs for workflow manager", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Maxime Maillet<[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"request-promise-native": "^1.0.5" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
reply_do_api_key: 'zPrWY3NXsgaW-5Spbs9ciA2' | ||
reply_ssii_api_key: '46cOPrjvAwRw9A4oRd3mrA2' | ||
reply_axel_api_key: 'Adw_Mfu80vjHkF2fZclvhg2' | ||
campaign_reply_doi: 30460 |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const request = require('request-promise-native'); | ||
|
||
module.exports.api = (apikey) => { | ||
return endpointReply(apikey); | ||
}; | ||
|
||
/** | ||
* @param apiKey | ||
* @returns {{send: (function(*=, *=, *=))}} | ||
*/ | ||
const endpointReply = (apiKey) => { | ||
return { | ||
send: (method, endpoint, params) => { | ||
return sendRequest(method, endpoint, params, apiKey); | ||
} | ||
}; | ||
}; | ||
|
||
/** | ||
* Send request to reply | ||
* @param method | ||
* @param endpoint | ||
* @param params | ||
* @param apiKey | ||
* @returns {*} | ||
*/ | ||
function sendRequest(method, endpoint, params, apiKey) { | ||
if (apiKey === null || apiKey === undefined) { | ||
throw new Error('Missing api key'); | ||
} | ||
|
||
const options = { | ||
uri: `https://api.reply.io${endpoint}`, | ||
port: 443, | ||
method: method, | ||
pathname: '', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'X-Api-Key': apiKey | ||
} | ||
}; | ||
|
||
if (options.method === 'GET') { | ||
options['qs'] = params; | ||
} else { | ||
options['body'] = JSON.stringify(params); | ||
} | ||
|
||
return request(options).then((data) => { | ||
if (data) { | ||
return JSON.parse(data); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: "User created from web site" | ||
id: user-created | ||
|
||
requirements: | ||
data: | ||
- hostname: 'adequancy.com' | ||
|
||
stages: | ||
- lehibou_do_created: | ||
job: add_reply | ||
data: | ||
- api_key: "%reply_do_api_key%" | ||
- campaign_id: "%campaign_reply_doi%" | ||
|