If you want to send a single SMS using Twilio you'll need a Twilio account, a phone number to send them from, and of course you'll need to know the destination phone number and the content of the message. Once you have these you can send your message with a single API call either with a direct HTTP request, or using any of our helper libraries. Check out our Programmable SMS Quickstarts for more details.
What if you need to send a hundred messages? Or a thousand? Or even more? In this post I'll talk through the challenges you may face as you scale up and how to get past them. Code samples will be in Java but the same principles apply with any programming language.
Sending a single SMS
Sending one SMS with Java is covered in this blog post. Feel free to go and read it, …
Photo courtesy of Pixabay (CC BY 2.0)
Whether you are a seasoned investor, downloaded RobinHood when the r/wallstreetbets events overtook the news cycle, or are keen to play with a new API, you can never have too many methods of checking the latest stock prices. You will build a bot for WhatsApp that will message a user basic stock quote information when they send in a valid ticker symbol.
Did you know you can code a Java app in under 5 minutes to send an SMS using the Twilio API? Probably closer to 2, once you've got the tools installed. You'll need:
- An installation of Java 8 or newer - I recommend SDKMAN! for installing and managing Java versions.
- A Java IDE - I like IntelliJ IDEA but if you have a favourite that's cool too.
- A Twilio account (if you don't have one yet, sign up for a free account here and receive $10 credit when you upgrade)
- A Twilio phone number that can send and receive SMS
The easiest way to call the Twilio API is with the Twilio Java Helper Library. In this I'll give examples using the Apache Maven build tool which will download and manage the dependency and packaging the project. You can get up to speed with Maven in 5 Minutes, …
If you're wondering how to send SMS from Java code, we've got you covered already. However, people are increasingly expecting to be able to converse with companies and services rather than just get a never-ending stream of notifications. To build really engaging and interactive apps you're going to want to respond to incoming messages too.
To do that, you will need to configure a URL in your Twilio console. Incoming messages will trigger HTTP requests to that URL, and the response to those webhook requests will determine what happens next, including sending responses. Responses should be written in an XML dialect called Twilio Markup Language, or TwiML.
In this post I'll walk you through setting up a web server using Spring Boot to do just that.
Getting set up
Before we get started, you'll need:
- An installation of Java 8 or newer - I recommend SDKMAN! for installing …
Lorsque quelque chose ne tourne pas rond dans une application Java en cours d'exécution, le premier indice est souvent l'impression de lignes à l'écran qui ressemblent à peu près à ce qui suit :
Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting! at com.myproject.module.MyProject.badMethod(MyProject.java:22) at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18) at com.myproject.module.MyProject.anotherMethod(MyProject.java:14) at com.myproject.module.MyProject.someMethod(MyProject.java:10) at com.myproject.module.MyProject.main(MyProject.java:6)
Ceci est une Stacktrace, et dans ce blog post, je vais vous expliquer de quoi il s'agit, comment ils sont générés et comment les lire et les comprendre. Si ça à déjà l’air pénible, lisez la suite...
Anatomie d'une Stacktrace
Habituellement, une Stacktrace s'affiche lorsqu'une Exception n'est pas gérée correctement dans le code. Il peut s'agir d'un des types d'exception intégrés de base dans Java, ou d'une exception customisée créée par un programme ou une librairie.
La Stacktrace contient le type d'exception et un message, ainsi qu'une liste de tous les …
Twilio is all about powering communication and doing it conveniently and fast in any language.
In this article, you'll be using your handy dandy command line and writing a couple of lines of Java code to send an SMS in an insanely fast manner. So why wait? Let's get started!
- A free or paid Twilio account. If you are new to Twilio get your free account now! (If you sign up through this link, Twilio will give you $10 credit when you upgrade.)
- Some prior knowledge of Java or a willingness to learn.
- A smartphone with active service, to test the project
We’ll start off by creating a directory to store the files of our project. Inside your favorite terminal, enter:
When you want to send an SMS or a WhatsApp message using Twilio's API, the programming model is straightforward: You call the API and the message gets sent. Responding to incoming messages is a different question. When the message arrives Twilio needs to find out how to handle it, and the mechanism we use is the Webhook. You configure your Twilio number with a URL and the platform makes a request to it passing some details about the incoming message - your app's response decides what happens next.
This means your app needs a public URL, which in turn means that you need some hosting. In the last few years serverless platforms have become popular for this, because they alleviate many of the pains of hosting. You provide code, which can handle an individual request, and the platform takes care of routing, scaling and most other concerns. Java's no …
One useful and common way to use Twilio is to create a phone number which forwards to your real phone. You can hand out the Twilio number to colleagues or customers and take business calls on your personal phone without worrying about handing out your real phone number. This also gives you a lot of options for how to handle these calls - you have the full power of Twilio at your disposal.
In this post I'll show you how to create a voicemail system that will jump in when your cell number is busy, or when you don't answer the call. It will play a message to your caller, then record their message and text you a link to the recording when it's done.
Primer: How Twilio Handles Calls
When someone dials your Twilio number, an HTTP request is sent to a URL that you provide. The web server …
Java 8 was released in 2014, and introduced a raft of new language features such as Lambdas and the Streams API. A lot has happened since 2014 - Java is now at version 15, but industry surveys consistently report 8 as the most widely-used version, with very few developers using 7 or lower.
In October this year, the Twilio Java Helper Library was updated to use Java 8 features in release 8.0.0. This new major version reflects the fact that the library no longer supports Java 7.
One Java 8 API which sometimes gets overlooked is the CompletionStage API, usually accessed through the CompletableFuture class. The CompletionStage API lets programmers define pipelines of asynchronous operations for data, and handles the asynchronous behaviour for you. You define what you want to happen, and Java takes care of when it can happen.
In this post I'll show how you …
[header image credit: NASA Astronomy Picture Of the Day, Sep 15 2020]
Happy Java 15 release day! This release marks three years since the start of the six-monthly release schedule and I am still appreciating the speed of new features and the insight it's giving into what's coming up in Java's future.
In Java 15 there are improvements to tooling, security, cross-platform consistency, efficiency and performance. You can read the full release notes and the list of major features, which are designated a Java Enhancement Proposal (JEP) number. In this post I've selected a few features which I think are interesting for developers.
The features I've selected are a mix of fully-released and "preview" features (more on these later).