Skip to content

Commit 2aacc8e

Browse files
authored
Feature/1208 health desk bot (#10)
* CHECK-1208: Kill http-server if test not running on CI * CHECK-1208: Will posttest exit with code 0, please? * CHECK-1208: Fix env var name. LOL * CHECK-1208: What is wrong with me?? * CHECK-1208: Fix READMEs; Run health-desk-bot locally
1 parent 42cf767 commit 2aacc8e

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ This bot is at `exif.js`. It does the following:
2121
* Listens to the `create_project_media` event. If it's an uploaded image, it extracts EXIF data and posts it to Check as a comment, with a link for the full report.
2222
* Listens to the `create_annotation_task_geolocation` and `update_annotation_task_geolocation`. If it's an uploaded image, it extracts GPS data, geocodes it and posts the result as a task response to any **unanswered** geolocation task.
2323

24-
## Usage
24+
### 3. Health Desk Bot
25+
26+
* Listens to event `create_project_media` events and looks up similar content in Health Desk articles indexed in Alegre.
27+
28+
See details in `./health-desk-bot/README.md`
29+
30+
## Usage (Deploying to AWS)
2531

2632
* Copy `config.js.example` to `config.js` and define your configurations
2733
* Run `npm run build`
@@ -32,7 +38,6 @@ This bot is at `exif.js`. It does the following:
3238
## Local usage
3339

3440
* Copy `config.js.example` to `config.js` and define your local configurations with `checkApiUrl: http://localhost:3000`.
35-
* Run `npm run exif` or `npm run youtube` to spin up a local server for either bot - note the port number.
3641
* Start Check locally
37-
* Find out the local host IP from the Check container as per https://stackoverflow.com/a/33103501
38-
* On the Check side, the bot request URL is the IP above with the port obtained when starting the bot.
42+
* The `check-bots` container should start `server.js` on port `8586`
43+
* On the Check side, the bot request URL should be set to `http://bots:8586/<bot-slug>` ('exif', 'youtube' or 'health-desk').

health-desk-bot/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Health Desk Bot
2+
3+
This bot listens for new item creation events and it looks up similar content in Health Desk articles indexed in Alegre.
4+
The functionality is split across two different lambda functions.
5+
6+
`health-desk-bot-lambda`, receives the events from Check-API and starts the lookup jobs by the second lambda `health-desk-bot-lambda-bg` which will respond with a note to the Check item if the content matches a Health Desk article.
7+
8+
## Usage
9+
10+
The Health Desk Bot depends on having the Health Desk articles indexed in Alegre.
11+
This first step ensures this prerequisite.
12+
13+
### 1. Indexing Health Desk content from CSV file in Alegre
14+
15+
* Copy `config.js.example` to `config.js` and define your configurations
16+
* Run `node ingest-csv.js <csv-file>`
17+
18+
### 2. Usage (Deploying to AWS)
19+
20+
For the first lambda `health-desk-bot-lambda`:
21+
22+
* Copy `config.js.example` to `config.js` and define your configurations
23+
* Run `npm run build`
24+
* Create an AWS Lambda function with an API gateway and upload the ZIP file from the previous step
25+
* Copy the API gateway URL as the Request URL of the Check API bot
26+
27+
For the second lambda `health-desk-bot-lambda-bg`:
28+
29+
* Copy `config.js.example` to `config.js` and define your configurations
30+
* Run `npm run build`
31+
* Create an AWS Lambda function - no API gateway required - and upload the ZIP file from the previous step
32+
* It's important to add this lambda to the right VPC in AWS so it can access Alegre
33+
34+
## Local usage
35+
36+
* Copy `config.js.example` to `config.js` and define your local configurations with `checkApiUrl: http://localhost:3000`.
37+
* Start Check locally
38+
* The `check-bots` container should start `server.js` on port `8586`
39+
* On the Check side, the bot request URL should be set to `http://bots:8586/health-desk`

health-desk-bot/alegre-data-ingest/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

health-desk-bot/health-desk-bot-lambda-bg/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"axios": "^0.24.0",
1515
"lokka": "^1.7.0",
1616
"lokka-transport-http": "^1.6.1"
17-
}
17+
},
18+
"scripts": {
19+
"build": "rm -f health-desk-bot-lambda-bg.zip && zip -9 -r --exclude=*configurator* --exclude=*test* health-desk-bot-lambda-bg.zip * && echo 'Now upload health-desk-bot-lambda-bg.zip to AWS Lambda'",
20+
},
1821
}

health-desk-bot/health-desk-bot-lambda/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
"axios": "^0.24.0",
1616
"lokka": "^1.7.0",
1717
"lokka-transport-http": "^1.6.1"
18-
}
18+
},
19+
"scripts": {
20+
"build": "rm -f health-desk-bot-lambda.zip && zip -9 -r --exclude=*configurator* --exclude=*test* health-desk-bot-lambda.zip * && echo 'Now upload health-desk-bot-lambda.zip to AWS Lambda'",
21+
},
1922
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"scripts": {
2424
"pretest": "http-server -p 7777 test &",
2525
"test": "mocha",
26+
"posttest": "[ -z $CONTINUOUS_INTEGRATION ] && pkill -f http-server || :",
2627
"build": "rm -f check-bots.zip && zip -9 -r --exclude=*configurator* --exclude=*test* check-bots.zip * && echo 'Now upload check-bots.zip to AWS Lambda'",
2728
"start": "node server.js"
2829
},

server.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ functions.forEach(function(name) {
3636
response.status(500).end();
3737
}
3838
});
39+
40+
app.post('/health-desk', function(request, response){
41+
const lambda = require('./health-desk-bot/health-desk-bot-lambda-bg').handler;
42+
console.log('health-desk', util.inspect(request.body));
43+
try {
44+
lambda(request.body, null, () => {}).then(() => {
45+
response.end();
46+
}, (error) => {
47+
console.error(error.message);
48+
response.status(500).end();
49+
});
50+
}
51+
catch (e) {
52+
console.error(e.message);
53+
response.status(500).end();
54+
}
55+
});
3956
});
4057

4158
console.log('Starting check-bots on port ' + port);

0 commit comments

Comments
 (0)