简体   繁体   中英

Storing SMS received through Twilio in a database

I'm building a website that allows people to receive SMS messages online through Twilio.

I was planning on receiving the data through Twilio and then storing it in a database. Here is the quick example database schema that I came up with to handle this:

CREATE TABLE InboundSMS(
   MessageSid            TEXT,
   SmsSid                TEXT,
   AccountSid            TEXT,
   MessagingServiceSid   TEXT,
   From                  TEXT,
   To                    TEXT,
   Body                  TEXT,
   NumMedia              TEXT
);

But as I was reading the documentation I saw the below regarding MessageSid .

A 34 character unique identifier for the message. May be used to later retrieve this message from the REST API.

This lead me to question do I even need to store the received SMS messages in my own database? Can I just leave them stored on Twilio and retrieve them using the API?

What is the suggest thing to do here? How long are they kept for on Twilio?

Twilio developer evangelist here.

You could absolutely use Twilio as the store for these messages. We don't delete SMS messages so you can always look them up.

However, it depends on how you want to access the messages in your application. You can filter the list of SMS messages in various ways, but that might not apply to how you want to use them. There are also performance benefits to storing your messages inside your own database where you can access them with a connected database driver rather than over HTTP.

If you do want to keep them, you could very well use the MessageSid as the key field on your database table to match the way that Twilio stores the message.

Also, note that the MessageSid and SmsSid are equal. SmsSid is just a legacy value kept for backwards compatibility with an older version of the API.

Let me know if this helps at all.

Twillio will store your messages indefinitely until you delete them, however they do charge for storage.

Twilio bills for storage on a monthly basis. The first 5GB per month is stored free of charge, additional storage is charged at 20¢ per GB per month.

If you want to save a few bucks, better store them locally and delete them from Twilio upon inserting into local storage. It's probably going to be quicker to retrieve them from a local database anyway.

Makes sense that the Twilio employee would suggest you store remotely so they can make a few bucks :P

https://www.twilio.com/help/faq/sms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM