diff --git a/README_DEVELOPER.md b/README_DEVELOPER.md
index cff07b4..1ffe10e 100644
--- a/README_DEVELOPER.md
+++ b/README_DEVELOPER.md
@@ -13,7 +13,15 @@ The following notes should help set up REDCap with What's App by Twilio
6. Create a Message Service to handle these messages and associate it to your sender
7. You must register approved What's App Templates. What's App and Twilio have complex rules about what content you can sent to a What's App number. The content depends on whether or not your are in an 'open session' or not. An open session lasts 24 hours and begins when a participant replies to your phone number. In most cases you will NOT have an open session with a participant and will have to use a 'template' to message them. We suggest creaing an 'ice breaker' template that can be used to open a new open session.
+## Local development
+#### Getting inbound requests to work properly
+Under the PACE-DEV developer settings in the integration tab make sure to set the webhook url:
+- `[NGROK_URL]/api/?type=module&prefix=whats-app-alerts&page=pages%2Finbound&NOAUTH`
+- Ignore the delivery status callback url (this is set in overridden in EM System settings)
+- Phone number designated in EM settings determines which inbound callback to use (prod and dev will be different)
+
TODO: Document better the next time someone goes through this process... It was long and difficult for us the first time around.
+TODO: Second time around it was still very complex
@@ -36,4 +44,8 @@ TODO: Document better the next time someone goes through this process... It was
## XDebug configuration
1. Each time refreshing ngrok urls, you must update path mappings in PHPStorm for Xdebug
-2. Add /var/www/html as the path mapping to the www folder on the server to the new entry
+2. In the upper right hand corner click edit configuations
+3. Create a new remote debug service copying the newly refreshed NGROK url as the host
+ - Ex : `c17a-99-35-20-190.ngrok-free.app`
+4. Update path mappings of www folder to /var/www/html
+
diff --git a/WhatsAppAlerts.php b/WhatsAppAlerts.php
index 028908d..4f409eb 100644
--- a/WhatsAppAlerts.php
+++ b/WhatsAppAlerts.php
@@ -30,6 +30,34 @@ class WhatsAppAlerts extends \ExternalModules\AbstractExternalModule {
private $wah;
+
+ public function redcap_save_record ( int $project_id, string $record = NULL, string $instrument, int $event_id, int $group_id = NULL, string $survey_hash = NULL, int $response_id = NULL, int $repeat_instance = 1 ) {
+ /**
+ * Required function that executes before redcap_email
+ * This function will set the URL field in enrollment, so it can be sent via What's App alerts
+ * Alert execution (email hook) triggers before default save, thus: this workaround will ensure the field is never empty
+ */
+ $pSettings = $this->getProjectSettings();
+
+ if(empty($_POST[$pSettings['url-field']])) { // execute only the first time enrollment is saved -- survey url has not been calculated
+ $pro = new \Project($project_id);
+ $primary_field = $pro->table_pk;
+ $pSettings = $this->getProjectSettings();
+
+ $url = \REDCap::getSurveyLink($record, $pSettings['survey-instrument'], $pSettings['survey-event'], '1', $project_id);
+ $saveData = [
+ [
+ $primary_field => $record,
+ $pSettings['url-field'] => $url,
+ ]
+ ];
+
+ $this->emLog("Saving url data for project $project_id, record $record. Url: $url");
+ // Save data using REDCap's saveData function
+ $res = \REDCap::saveData($project_id, 'json', json_encode($saveData), 'overwrite');
+ }
+ }
+
/**
* Generic REDCap Email Hook
*/
diff --git a/config.json b/config.json
index 7a46eef..2897225 100644
--- a/config.json
+++ b/config.json
@@ -21,7 +21,8 @@
"permissions": [
"redcap_email",
"redcap_module_system_enable",
- "redcap_every_page_top"
+ "redcap_every_page_top",
+ "redcap_save_record"
],
"enable-every-page-hooks-on-system-pages": false,
@@ -110,7 +111,25 @@
"name": "Enable Debug Logging
(optional) Requires installation and configuration of emLogger",
"required": false,
"type": "checkbox"
- }
+ },
+ {
+ "key": "survey-instrument",
+ "name": "Survey Link Instrument
(optional)Specific form that will be used to generate the survey link sent via What's App after enrollment is saved",
+ "required": false,
+ "type": "form-list"
+ },
+ {
+ "key": "survey-event",
+ "name": "Survey Link Event
The event / arm the survey link should be in ",
+ "required": true,
+ "type": "event-list"
+ },
+ {
+ "key": "url-field",
+ "name": "Url Field
The field the survey url (sent via what's app) for consent will be stored within",
+ "required": true,
+ "type": "field-list"
+ }
],