checkuponme / Spoke

Politics Rewired's fork of Spoke, now forked for CheckUpOn.Me.
GNU General Public License v3.0
5 stars 1 forks source link

(node:92573) UnhandledPromiseRejectionWarning: error: invalid input value for enum messaging_service_type: "null" #14

Closed TheRealAlexV closed 4 years ago

TheRealAlexV commented 4 years ago

Problem

When adding contacts via csv file to a campaign, if twilio is set as the default messaging service in the .env file (DEFAULT_SERVICE=twilio) the import hangs because we have not added any messaging services to the database yet and thus matching a contacts to messaging services is failing. The full error is below:

11:02:05 PM server.1 |  (node:92573) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(),
11:02:05 PM server.1 |  >  Buffer.allocUnsafe(), or Buffer.from() methods instead.
11:02:15 PM server.1 |  (node:92573) UnhandledPromiseRejectionWarning: error: invalid input value for enum messaging_service_type: "null"
11:02:15 PM server.1 |      at Connection.parseE (/opt/Spoke-1.7.1/node_modules/pg/lib/connection.js:567:11)
11:02:15 PM server.1 |      at Connection.parseMessage (/opt/Spoke-1.7.1/node_modules/pg/lib/connection.js:391:17)
11:02:15 PM server.1 |      at Socket.<anonymous> (/opt/Spoke-1.7.1/node_modules/pg/lib/connection.js:129:22)
11:02:15 PM server.1 |      at Socket.emit (events.js:311:20)
11:02:15 PM server.1 |      at Socket.EventEmitter.emit (domain.js:482:12)
11:02:15 PM server.1 |      at addChunk (_stream_readable.js:294:12)
11:02:15 PM server.1 |      at readableAddChunk (_stream_readable.js:275:11)
11:02:15 PM server.1 |      at Socket.Readable.push (_stream_readable.js:209:10)
11:02:15 PM server.1 |      at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
11:02:15 PM server.1 |  From previous event:
11:02:15 PM server.1 |      at Client_PG._query (/opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/dialects/postgres/index.js:245:12)
11:02:15 PM server.1 |      at Client_PG.query (/opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/client.js:192:17)
11:02:15 PM server.1 |      at Runner.<anonymous> (/opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/runner.js:138:36)
11:02:15 PM server.1 |  From previous event:
11:02:15 PM server.1 |      at /opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/runner.js:47:21
11:02:15 PM server.1 |      at processImmediate (internal/timers.js:456:21)
11:02:15 PM server.1 |      at process.topLevelDomainCallback (domain.js:137:15)
11:02:15 PM server.1 |  From previous event:
11:02:15 PM server.1 |      at Runner.run (/opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/runner.js:33:30)
11:02:15 PM server.1 |      at Raw.Target.then (/opt/Spoke-1.7.1/node_modules/rethink-knex-adapter/node_modules/knex/lib/interface.js:23:43)
11:02:15 PM server.1 |  (node:92573) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async
11:02:15 PM server.1 |  >   function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhand
11:02:15 PM server.1 |  >  led promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_m
11:02:15 PM server.1 |  >  ode). (rejection id: 1)
11:02:15 PM server.1 |  (node:92573) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not
11:02:15 PM server.1 |  >  handled will terminate the Node.js process with a non-zero exit code.

If you want to take on this issue, I can give you access to our development spoke server which has an active twilio api setup on it. Just let me know.

To reproduce this issue on a local machine, you must setup a twilio account and add a pair of test credentials as per these docs: https://www.twilio.com/docs/iam/test-credentials

Resolution

Ben Chrobot one of the lead politics Rewired devs (what this spoke is forked from) offered this resolution:

"Based on the logs it seems like you have not added any messaging services to the database yet and thus matching a contacts to messaging services is failing. We use the insert-invite.js script to generate an invite that will auto-populate a messaging service when the invite is redeemed. You can insert a messaging service manually, but will need to use the symmetric-encrypt utility to encrypt the auth token."

To close

I'm not a JS guy so I'm a little unclear on ben's instructions. I'm thinking a backend guy can handle this better than I can. When this is solved, can you just document in plain non-programmer lingo (something a devops guy will understand) how to resolve this? This won't be the last time we run into this issue.

TheRealAlexV commented 4 years ago

The insert invite script can be run using:

export SERVICE_TYPE="twilio"
export MESSAGING_SERVICE_SID="MSTwilioMessagingServiceSID"
export ACCOUNT_SID="ACTwilioAccountSID"
export UNENCRYPTED_AUTH_TOKEN="SecretTwilioAuthToken"

yarn util:insert-invite myinvitename --include-env

If you already have an organization set up, it may be easier just to insert the messaging service records manually:

# Make sure that SESSION_SECRET is set to your production value in .env before:
$ node ./dev-tools/symmetric-encrypt.js SecretTwilioAuthToken
# copy the output

$ psql "postgres://my_prod_postgres_conncection_string"

psql> \set my_existing_org_id 1
psql> insert into messaging_service (organization_id, service_type, messaging_service_sid, account_sid, encrypted_auth_token)
values (:my_existing_org_id, 'twilio', 'MSTwilioMessagingServiceSID', 'ACTwilioAccountSID', 'OutputFromSymmetricEncrypt');