
Twilio SMS Parser
Pricing
Pay per usage
Go to Store

Twilio SMS Parser
Parse incoming Twilio SMS message.
0.0 (0)
Pricing
Pay per usage
2
Total users
25
Monthly users
2
Runs succeeded
0%
Last modified
4 years ago
Dockerfile
# Dockerfile contains instructions how to build a Docker image that# will contain all the code and configuration needed to run your actor.# For a full Dockerfile reference,# see https://docs.docker.com/engine/reference/builder/
# First, specify the base Docker image. Apify provides the following# base images for your convenience:# apify/actor-node-basic (Node.js on Alpine Linux, small and fast)# apify/actor-node-chrome (Node.js + Chrome on Debian)# apify/actor-node-chrome-xvfb (Node.js + Chrome + Xvfb on Debian)# For more information, see https://docs.apify.com/actor/build#base-images# Note that you can use any other image from Docker Hub.FROM apify/actor-node-basic
# Second, copy just package.json since it should be the only file# that affects "npm install" in the next step, to speed up the buildCOPY package.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --only=prod --no-optional \ && echo "Installed NPM packages:" \ && npm list || true \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Optionally, specify how to launch the source code of your actor.# By default, Apify's base Docker images define the CMD instruction# that runs the Node.js source code using the command specified# in the "scripts.start" section of the package.json file.# In short, the instruction looks something like this:## 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_MODE11 ? TEST_MESSAGE_DATA12 : (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
{ "name": "twilio-sms-parser", "version": "0.0.1", "dependencies": { "apify": "^0.20.2", "moment": "^2.24.0" }, "scripts": { "start": "node main.js" }, "author": "Youcef Islam Remichi - Onidivo"}