How to set up Twilio for local development
In the first part of this tutorial we showed you how to make npm package integrations directly into your Advanced Cloud Code. But let’s say you want to test something on your computer before deploying it on SashiDo’s Cloud Code. This tutorial is for Mac OS X (for other OS should something similar)
First you should install nvm (Node Version Manager - Simple bash script to manage multiple active node.js versions). Here’s explanation how to do it: link. Command is
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
You should also have Node.js installed, you can download it from here. But we’ll show how to do it with the NVM. Run in your terminal the following command:
nvm install v6.2.1
Clone the repository, if you haven’t done it yet.
git clone firstname.lastname@example.org:parsegroundapps/pg-app-yourapp-id.git
Install twilio, here is explained how to do it link. We suggest you to use the command:
npm install --save twilio
Command --save will automatically write it in package.json. It’s a good practice to use it, because sometimes a programmer forgets to add the dependency and to push it to the server. The code won’t work as a result.
You should add node_modules directory to the git ignore file, because they’ll be installed on the server automatically by SashiDo.
echo 'node_modules' >> .gitignore
Let’s create a new file which will keep our test code: twilio.js in the cloud directory. Don’t forget to require it in main.js, otherwise it’ll not work.
Let’s write a simple function in twilio.js, which will send a SMS to a number by your choice.
You can find 'ACCOUNT_SID' and 'AUTH_TOKEN' in Twilio’s Dashboard, here is Twilio’s documentation in case you need it.
In order to test, you’ll need some database. You can use your application’s database. Go to SashiDo’s Dashboard, App Settings -> Security & Keys -> Database URL. Copy & Paste in index.js:
Run Parse Server in Node.js with command
Open a new tab of the terminal and write the following POST request to do the test:
curl -X POST \ -H 'X-Parse-Application-Id: myAppId' \ -H 'X-Parse-REST-API-Key: key' \ http://localhost:1337/1/functions/inviteWithTwilio
Check the phone for the results, if you followed this tutorial correctly, you should get the SMS:
If you’re happy with the results, it’s time to deploy the code. Git add, git commit, git push your changes
git add . git commit -am 'Add twillio integration' git push
**Now you can smoothly enjoy building complex apps with the power, given by SashiDo and Advanced Cloud Code.** If you have any difficulties or need help - reach us at email@example.com .
Happy coding :)