Send Sms with Twilio in your Graphcool project 馃巵
graphcool add-template messaging/twilioThe add-template command is performing three major steps:
- Download the source files from the
srcdirectory and put them into your service'ssrcdirectory (into a subdirectory calledtwilio). - Download the contents from
graphcool.ymland append them as comments to your service'sgraphcool.yml. - Download the contents from
types.graphqland append them as comments to your service'stypes.graphql.
In order for the changes to take effect, you need to manually uncomment all the lines that have been added by the add-template command.
You need to configure these credentials as environment variables:
TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKEN
You can receive them after signing up at Twilio.
To manage your environment variables, you can use a tool like direnv.
Finally, you need to install the node dependencies and apply all the changes you just made by deploying the service:
npm install
graphcool deployGo to the Graphcool Playground:
graphcool playgroundHook into the function logs:
graphcool logs -f sendSms --tailRun this mutation to create a new email:
mutation {
sendSms(
to: "__RECIPIENT_NUMBER__"
from: "__SENDER_NUMBER__"
body: "Hey there, check this cool image!"
mediaUrl: "https://climacons.herokuapp.com/clear.png"
) {
sid
}
}A new SMS will be sent to the specified number. This is also reflected in the function logs.
Note: when testing out Twilio, both numbers have to be verified first.
