Twilio SMS Parser
Try for free
No credit card required
Go to Store
Twilio SMS Parser
onidivo/twilio-sms-parser
Try for free
No credit card required
Parse incoming Twilio SMS message.
Dockerfile
1# Dockerfile contains instructions how to build a Docker image that
2# will contain all the code and configuration needed to run your actor.
3# For a full Dockerfile reference,
4# see https://docs.docker.com/engine/reference/builder/
5
6# First, specify the base Docker image. Apify provides the following
7# base images for your convenience:
8# apify/actor-node-basic (Node.js on Alpine Linux, small and fast)
9# apify/actor-node-chrome (Node.js + Chrome on Debian)
10# apify/actor-node-chrome-xvfb (Node.js + Chrome + Xvfb on Debian)
11# For more information, see https://docs.apify.com/actor/build#base-images
12# Note that you can use any other image from Docker Hub.
13FROM apify/actor-node-basic
14
15# Second, copy just package.json since it should be the only file
16# that affects "npm install" in the next step, to speed up the build
17COPY package.json ./
18
19# Install NPM packages, skip optional and development dependencies to
20# keep the image small. Avoid logging too much and print the dependency
21# tree for debugging
22RUN npm --quiet set progress=false \
23 && npm install --only=prod --no-optional \
24 && echo "Installed NPM packages:" \
25 && npm list || true \
26 && echo "Node.js version:" \
27 && node --version \
28 && echo "NPM version:" \
29 && npm --version
30
31# Next, copy the remaining files and directories with the source code.
32# Since we do this after NPM install, quick build will be really fast
33# for most source file changes.
34COPY . ./
35
36# Optionally, specify how to launch the source code of your actor.
37# By default, Apify's base Docker images define the CMD instruction
38# that runs the Node.js source code using the command specified
39# in the "scripts.start" section of the package.json file.
40# In short, the instruction looks something like this:
41#
42# CMD npm start
main.js
1const Apify = require('apify');
2const moment = require('moment');
3
4const { log } = Apify.utils;
5const IS_TEST_MODE = process.env.IS_TEST_MODE === 'true';
6const TEST_MESSAGE_DATA = 'ToCountry=US&ToState=NJ&SmsMessageSid=SMba0d9db1db81dda8f486e5cd53015502&NumMedia=0&ToCity=HACKENSACK&FromZip=16915&SmsSid=SMba0d9db1db81&FromState=PA&SmsStatus=received&FromCity=GENESEE&Body=589665+is+your+activation+code.&FromCountry=US&To=%2B12015842345&ToZip=07930&NumSegments=1&MessageSid=SMba0d9db1db81dda8f48&AccountSid=ACd7d487f65588e45a5sdsds&From=%2B18142223452&ApiVersion=2010-04-01';
7
8Apify.main(async () => {
9 log.info('Getting message data from input');
10 const messageDataAsString = IS_TEST_MODE
11 ? TEST_MESSAGE_DATA
12 : (await Apify.getInput()).toString();
13
14 const messageData = {};
15 for (const [k, v] of new URLSearchParams(messageDataAsString).entries()) {
16 messageData[k] = v;
17 }
18 messageData.receivedAt = moment.utc().valueOf();
19
20 const phoneNbre = messageData.To.replace('+', '00');
21
22 const sharedKvs = await Apify.openKeyValueStore('twilio-sms-parser');
23
24 log.info(`Saving message data for phone number "${phoneNbre}"`);
25 await sharedKvs.setValue(phoneNbre, messageData);
26});
package.json
1{
2 "name": "twilio-sms-parser",
3 "version": "0.0.1",
4 "dependencies": {
5 "apify": "^0.20.2",
6 "moment": "^2.24.0"
7 },
8 "scripts": {
9 "start": "node main.js"
10 },
11 "author": "Youcef Islam Remichi - Onidivo"
12}
Developer
Maintained by Community
Actor Metrics
1 monthly user
-
2 stars
0% runs succeeded
Created in Mar 2020
Modified 4 years ago
Categories