Is it possible to change the Messaging URL callback with the Twilio API?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 18:03:20

问题


Hello and thank you for reading. Is it possible to change the Messaging URL callback with the Twilio API?


回答1:


You need to POST to an IncomingPhoneNumber instance resource.

You can do it with curl, or if you're using another language read these docs,
https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-update-an-incomingphonenumber&code-language=curl&code-sdk-version=json (and select another language for the sample code).

You will need to know:

SUB-ACCOUNT-SID \\ the sid for the account where the phone number belongs to
PHONE-NUMBER-SID \\ the sid of the phone number you want to change the URL
MASTER-ACCOUNT-SID \\ your Twilio master account sid
MASTER-ACCOUNT-TOKEN \\ your Twilio master account token

If you're not using sub-accounts SUB-ACCOUNT-SID and MASTER-ACCOUNT-SID are the same thing.


The command to change the URL to http://demo.twilio.com/docs/sms.xml (replace with your values):

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/SUB-ACCOUNT-SID/IncomingPhoneNumbers/PHONE-NUMBER-SID.json -d "SmsUrl=http://demo.twilio.com/docs/sms.xml" -u "MASTER-ACCOUNT-SID:MASTER-ACCOUNT-TOKEN"

Note: when you replace the values it looks something like this

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/AC0123456789abcdefabcdefabcdefabcd/IncomingPhoneNumbers/PN0123456789abcdefabcdefabcdefabcd.json -d "SmsUrl=http://demo.twilio.com/docs/sms.xml" -u "ACabcdefabcdefabcdefabcd0123456789:0123456789abcdefabcdefabcdefabcd"



回答2:


You can do so using the twilio api

const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.incomingPhoneNumbers('PN2a0747eba6abf96b7e3c3ff0b4530f6e')
  .update({
     accountSid: 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     smsUrl: 'http://demo.twilio.com/docs/sms.xml',
     voiceUrl: 'http://demo.twilio.com/docs/voice.xml'
   })
  .then(incoming_phone_number => console.log(incoming_phone_number.friendlyName))
  .done();


来源:https://stackoverflow.com/questions/46348307/is-it-possible-to-change-the-messaging-url-callback-with-the-twilio-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!