How can I receive a text message in Elixir?

So I want to build an app that people can randomly send text messages to – the app should receive the text message, which may include a graphic, and then process it. I will have to sign up and pay for a phone number, I suppose. But I don’t know how to connect a phone number with a phoenix app. Any ideas?

Thanks.

Your best bet is connecting via the twilio api or a similar product.

4 Likes

Some sms-as-a-service saas is probably the easiest way, but hooking up a gsm shield to your arduino to your rpi to your http-endpoint is probably the more expensive fun way!

(Amazon SNS can send messages for free to specific numbers you add to your sandbox, it (or probably another AWS service) may be able to receive messages for free too. Worth peeking at if you’re planning to work around one specific number.)

4 Likes

Did U solve this? I have the same question and have not been able to make receiving SMS/texts work.

Look for technical solution rather than highlevel overview.

Sending not receiving but interesting blog

1 Like

I use a system which might be seen as arcane nowadays. I purchased this several years ago and we receive hundreds of texts, flawlessly I would say, each day: https://smsenabler.com/

We use the webhook option, so texts are forwarded straight into a remote system. (In my case Google Apps Script web app. But a Phoenix route would work too).

I believe we use an old Nokia with a cheap simcard with its own phone number, connected to an old laptop. (The setup is in an office remote to me, but I could check if someone is interested).

I suppose that getting the ‘old’ equiment together, paying for the higher energy costs and actually locating the equipment in a place that gets a gsm signal are current considerations. None of these were an issue at the time of installation for us.

I looked at cloud service providers at the time but I couldn’t find one that worked for us (A big consideration is that this way we got a country specific telephone number, due to the sim, which we publish to our customers.)

1 Like

If you go with hardware solutions, you could easily develop/download an application on android to relay the messages, of course if you want it to be as reliable as possible you will need to root the device and install it as a system application.

The problem with using old hardware or things like SIM800 is that most of them support only 2G, witch can be either disabled or not exist at all in your country, so the android solution ensures that you have access to latest hardware on the market.

1 Like

That’s useful information. I didn’t know so googled it and came up with this software: Forward Text Messages (SMS) To Rest API

Could be a good alternative, and certainly cheaper to set up / maintain than the one I mention.

(I won’t change my setup until it breaks down/causes a problem, due to its reliability. But your idea gives a safety net)

Even making a custom application is a trivial task, I have been using an application that sends sms from one of my phones to email via smtp and it works flawlessly now for half a year.

To make this setup more reliable it is recommended to connect to internet via ethernet cable (not wifi, as there are instances where wifi gets turned off on some devices in standby mode) and replace the battery with a direct connection to a power supply.

I’m thinking this is interesting. So I asked ChatGPT about this. I put it here for possible interest!

I have read this: If you want a hardware solution, you could easily develop an application on android to relay the SMS messages to a server; making a custom application is a trivial task, I have been using an application that sends sms from one of my phones to email via smtp and it works flawlessly now for half a year. These notes are written by a developer. So trivial is a relative term, I believe. Can you explain how to achieve this? You are teaching a technical person (engineer) but a non-developer. Indicate which bits almost certainly would need the technical person to ‘ask a developer friend’ to help (because actually, years of experience are needed for that part)

I understand that you’re a technical person, but not a developer. I’ll break down the process into steps and explain each step in a way that’s easy to understand. I’ll also indicate which parts might need assistance from a developer friend.

Here’s a high-level overview of what we want to achieve: Develop an Android application that listens for incoming SMS messages, and when a new message is received, the app will send the SMS content to a server.

Step 1: Setting up the development environment (DIY) First, you’ll need to set up the development environment for creating Android applications. You’ll need Android Studio, which is the official development environment provided by Google. You can download it from the Android Studio website (Download Android Studio & App Tools - Android Developers) and follow the installation instructions.

Step 2: Creating a new Android project (DIY) Once you have Android Studio installed, create a new project by selecting “New Project” and follow the prompts. Choose an application name, package name, and select “Phone and Tablet” as your target device. For the language, choose “Java” or “Kotlin” (whichever you’re more comfortable with, though Kotlin is recommended for new projects).

Step 3: Adding permissions to access SMS (DIY) In order to access SMS messages, you need to add the necessary permissions in the AndroidManifest.xml file. Add the following lines inside the <manifest> element:

xml

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />

Step 4: Creating a BroadcastReceiver for incoming SMS (Ask a developer friend) This step requires some coding knowledge. You need to create a BroadcastReceiver class that listens for incoming SMS messages. When a new message is received, the BroadcastReceiver will trigger a callback function with the message details. You can find examples online on how to create a BroadcastReceiver for incoming SMS messages in Java or Kotlin.

Step 5: Sending the SMS data to a server (Ask a developer friend) Once you have the BroadcastReceiver set up, you need to send the SMS data to a server. This involves making an HTTP request (POST request) with the SMS content as the payload. You can use libraries like Retrofit or HttpURLConnection for this purpose. You’ll need a server to accept these requests, which can be set up using a backend framework like Node.js, Django, or Flask. This step would require assistance from a developer friend if you’re not familiar with server-side programming.

Step 6: Testing the application (DIY) After completing the above steps, you can test the application on an Android device or an emulator. Make sure to grant the required permissions when prompted. Once everything is set up correctly, you should see the SMS messages being sent to the server when you receive new messages on the device.

Remember, while the DIY steps can be learned with some effort, the parts marked “Ask a developer friend” are more complex and might require more in-depth programming knowledge. It’s a good idea to collaborate with a developer friend to help you with these parts.

If, rather than sending to a server, the SMS go to email via smtp does this change / improve the complexity in any way?

Sending SMS messages to an email via SMTP instead of a server does change the complexity, but whether it’s an improvement depends on your perspective. Using SMTP might simplify the process, as you won’t need to set up a server to handle the incoming requests. However, you’ll still need to set up email credentials and configure the SMTP settings in your Android application.

Here’s a modified version of the earlier steps to send the SMS data to an email via SMTP:

Step 1: Setting up the development environment (DIY) (No change here)

Step 2: Creating a new Android project (DIY) (No change here)

Step 3: Adding permissions to access SMS (DIY) (No change here)

Step 4: Creating a BroadcastReceiver for incoming SMS (Ask a developer friend) (No change here)

Step 5: Sending the SMS data to an email via SMTP (Ask a developer friend) Instead of sending the SMS data to a server, you’ll send it to an email using SMTP. You can use libraries like JavaMail (JavaMail) or MailJet (https://www.mailjet.com/docs/code/java/) to send emails from your Android application. You’ll need to configure the SMTP settings with your email provider’s details (Gmail, Yahoo, etc.) and provide your email credentials.

Here’s a basic example of sending an email using JavaMail:

java

Properties props = new Properties();
props.put("mail.smtp.host", "your.smtp.server");
props.put("mail.smtp.port", "your.smtp.port");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("your.email@example.com", "your.email.password");
    }
});

try {
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("your.email@example.com"));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("destination.email@example.com"));
    message.setSubject("SMS Forward");
    message.setText("SMS from: " + senderPhoneNumber + "\n\n" + smsMessageBody);

    Transport.send(message);
} catch (MessagingException e) {
    throw new RuntimeException(e);
}

Replace the placeholders (e.g., “your.smtp.server”, “your.email@example.com”, etc.) with your email provider’s details and your credentials. Make sure to include the necessary dependencies in your project.

Step 6: Testing the application (DIY) (No change here)

While this approach eliminates the need to set up a server, it requires handling email credentials and SMTP configuration within your app. You should weigh the pros and cons of each method before deciding which one to use. If you’re not familiar with SMTP or email handling in general, it’s a good idea to ask a developer friend for help with this step.