Celebrate St Patrick's Day: Translate English to Gaelic with Twilio Serverless, SMS, and IBM Watson
Time to read: 2 minutes
Celebrate St. Patrick's Day on March 17th by texting a sentence to +13863564094 to translate it to Gaelic, and read on to learn how to build the app using IBM Watson, Twilio Functions, JavaScript, and the Twilio Serverless Toolkit.
Prerequisites
- A Twilio account - sign up for a free one here and receive an extra $10 if you upgrade through this link
- A Twilio phone number with SMS capabilities - configure one here
- Node.js installed - download it here
- IBM Cloud account - sign up for a free one here
Setup IBM Watson
Go to the IBM Watson Cloud Translator console, select the free Lite plan, and make a new service by clicking Create on the righthand panel.
Whoop whoop! You've just made your free Watson Translator service!
To get our required credentials, click the Navigation Menu in the top left corner.
Select Resource list from the dropdown menu followed by your language translator resource.
Keep this page with your API key and URL (which are unique to you) open--we'll use those in the next step!
Get Started with the Twilio Serverless Toolkit
The Serverless Toolkit is CLI tooling that helps you develop locally and deploy to Twilio Runtime. The best way to work with the Serverless Toolkit is through the Twilio CLI. If you don't have the Twilio CLI installed yet, run the following commands on the command line to install it and the Serverless Toolkit:
Create your new project and install the lone requirement ibm-watson
, an HTTP client library to make HTTP requests in Node.js, by running:
Make a .env file and add an environment variable for your IBM API key from the IBM Cloud page in the last step. In this blog post, the API key is called `WATSON_KEY`.
Make a Twilio Function with JavaScript
cd
into the \functions
directory and make a new file called translate.js containing the following code:
This code imports the Watson language translator, makes a Twilio Messaging Response object, authenticates to the Watson API using IBM Cloud Identity and Access Management (IAM), and passes the inbound message and the English to Gaelic `en-ga` model to the `translateParams` object`. You could also translate to or from other languages, listed here. We then return the inbound message translated to Gaelic and a St. Patrick's day image in our message response.
You can view the complete app on GitHub here.
Configure the Function with a Twilio Phone Number
To open up our app to the web with a public-facing URL, go back to the irishtranslator root directory and run twilio serverless:deploy
. Once you see a Function URL ending in /translate, go to the phone numbers section of your Twilio Console and select the Twilio number you purchased and scroll down to the Messaging section. Under A MESSAGE COMES IN change Webhook to Function and then under Service select irishtranslator, for Environment select dev-environment, and then for Function Path select /translate.
Click the Save button below and tada! You can now text your Twilio number a phrase, sentence, or paragraph and receive a response containing it translated to Gaelic.
What's Next for Twilio Serverless and APIs?
How are you celebrating St. Patrick's Day? Twilio's Serverless Toolkit makes it possible to deploy web apps quickly, Twilio Runtime seamlessly handles servers for you, and IBM Watson makes it easy to perform a variety of machine learning tasks.
Let me know online what you're building with Serverless and/or machine learning!
- Twitter: @lizziepika
- GitHub: elizabethsiegle
- Email: lsiegle@twilio.com
- Livestreams: twitch.tv/lizziepikachu
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.