NickD
NickD

Reputation: 191

get SMS history between specific twilio's phone and specific outbound phone TWILIO

Let's say I have 5 twilio's phone number, where I can send SMS to users. Is there any way to retrieve directly the list ordered by date from the SMS history of those number specifically, or I need to do 2 calls to the API inverting the from and to parameter, and after that, mix both of the data in an array and sort them by date.

Let say i want something like this ( does not work but you can see want i am trying to do)

client.messages.each({
    from: '14509153021' || '+5945863945',
    to: '+5945863945' || '14509153021',
},
    messages => {
      console.log(messages)
    }
);

I have this code snippet below that works, but i have to manually sort them by date and mix them in the same array to display correctly the history to my user interface :

client.messages.each({
  from: '+5945863945',
  to: '+14509153021',
},

    messages => {
      //add to temporary array 
    }

);

client.messages.each({
  from: '14509153021',
  to: '+5945863945',
},

    messages => {
      //add to temporary array 
    }

);

//mix all data to the same array ordered by date

Upvotes: 3

Views: 155

Answers (1)

philnash
philnash

Reputation: 73057

Twilio developer evangelist here.

I'm afraid you've answered your own question here. You need to do two calls to the API, inverting the From and To numbers.

Alternatively, you could just list all your messages and filter out by To and From numbers.

Upvotes: 3

Related Questions