Andrew Ahn
Andrew Ahn

Reputation: 21

How to read received SMS message from Twilio Programmable SMS API

I like to ask How to read all received SMS message from Twilio Programmable SMS API (based on certain date).

I managed to figure out how to read all SMS message sent but can't find much resources around how to fetch all received SMS message, not sent.

Below is how you can read sent SMS message, not received message (sent After certain date) Appreciate in advance.

        TwilioClient.Init(accountSid, authToken);

        var messages = MessageResource.Read(
            dateSentAfter: new DateTime(2018, 12, 6, 0, 0, 0)
            );
        foreach (var record in messages)
        {
            Response.Write(record.DateCreated + ", From: " + record.From + ", To:" + record.To + "</br>" + " Body: " +   record.Body + "</br></br>");
        }

Upvotes: 0

Views: 558

Answers (1)

Alan
Alan

Reputation: 10771

JavaScript use months 0 - 11 rather then 1 - 12.

So take this, using the date your currently have as the filter.

let a = new DateTime(2018, 12, 6, 0, 0, 0)
console.log(a)

Result: 2019-01-06T00:00:00.000Z

What you want is new DateTime(2018, 11, 6, 0, 0, 0)

Result: 2018-12-06T00:00:00.000Z

See if that fixes the issue.

The dateSent field is in both sent and received messages. You can set the To to your Twilio phone number to further reduce the dataset down to received SMS messages for that date.

Upvotes: 1

Related Questions