简体   繁体   English

将通过Twilio接收的SMS存储在数据库中

[英]Storing SMS received through Twilio in a database

I'm building a website that allows people to receive SMS messages online through Twilio. 我正在建立一个网站,使人们可以通过Twilio在线接收SMS消息。

I was planning on receiving the data through Twilio and then storing it in a database. 我打算通过Twilio接收数据,然后将其存储在数据库中。 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 . 但是,当我阅读文档时,我看到了以下与MessageSid有关的内容。

A 34 character unique identifier for the message. 消息的34个字符的唯一标识符。 May be used to later retrieve this message from the REST API. 以后可用于从REST API检索此消息。

This lead me to question do I even need to store the received SMS messages in my own database? 这使我产生疑问,我是否甚至需要将收到的SMS消息存储在自己的数据库中? Can I just leave them stored on Twilio and retrieve them using the API? 我可以只将它们存储在Twilio上并使用API​​检索它们吗?

What is the suggest thing to do here? 建议在这里做什么? How long are they kept for on Twilio? 他们在Twilio上待了多长时间?

Twilio developer evangelist here. Twilio开发者传道者在这里。

You could absolutely use Twilio as the store for these messages. 您可以绝对使用Twilio作为这些消息的存储。 We don't delete SMS messages so you can always look them up. 我们不会删除SMS消息,因此您可以随时查找它们。

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. 您可以通过多种方式过滤SMS消息列表 ,但这可能不适用于您希望使用它们的方式。 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. 将消息存储在自己的数据库中还可以提高性能,在这里您可以使用连接的数据库驱动程序而不是通过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. 如果确实要保留它们,则可以很好地将MessageSid用作数据库表上的键字段,以匹配Twilio存储消息的方式。

Also, note that the MessageSid and SmsSid are equal. 另外,请注意,MessageSid和SmsSid相等。 SmsSid is just a legacy value kept for backwards compatibility with an older version of the API. SmsSid只是保留的旧值,用于与旧版本的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. Twillio将无限期地存储您的消息,直到您删除它们为止,但是它们会收取一定的存储费用。

Twilio bills for storage on a monthly basis. Twilio每月收取存储费用。 The first 5GB per month is stored free of charge, additional storage is charged at 20¢ per GB per month. 每月的前5GB是免费存储的,额外的存储空间为每月每GB 20¢。

If you want to save a few bucks, better store them locally and delete them from Twilio upon inserting into local storage. 如果您想节省几块钱,最好将它们存储在本地,并在插入本地存储时将它们从Twilio中删除。 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 Twilio员工建议您远程存储是合理的,这样他们就可以赚到几块钱:P

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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