A Ruby Cloud Function for sending a message to a phone number using Twilio API.
Example input:
{
"message": "Hello from Open Runtimes 👋",
"receiver": "+421XXXXXXXXX"
}
Example output:
{
"messageId": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
List of environment variables used by this cloud function:
- TWILIO_ACCOUNT_SID - Twilio account SID
- TWILIO_AUTH_TOKEN - Twilio auth token
- TWILIO_SENDER - Sender's phone number from Twilio
ℹ️ Find your Account SID and Auth Token at twilio.com/console.
- Clone this repository, and enter this function folder:
$ git clone https://github.com/open-runtimes/examples.git && cd examples
$ cd ruby/send-sms-with-twilio
- Enter this function folder and build the code:
docker run --rm --interactive --tty --volume $PWD:/usr/code openruntimes/ruby:v2-3.1 sh /usr/local/src/build.sh
As a result, a code.tar.gz
file will be generated.
- Start the Open Runtime:
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key -e INTERNAL_RUNTIME_ENTRYPOINT=index.rb --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/ruby:v2-3.1 sh /usr/local/src/start.sh
Make sure to replace
secret-key
with your key.
Your function is now listening on port 3000
, and you can execute it by sending POST
request with appropriate authorization headers. To learn more about runtime, you can visit Ruby runtime README.
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in Appwrite docs.
- This example is compatible with Ruby 3.1. Other versions may work but are not guaranteed to work as they haven't been tested.