Twilio update webhook for number by python code - python

Is there any way to set webhook url for Twilio number by python code ??
something as: client.number('MY_TWILIO_NUMBER').update(webhook='ngrok.io')
???
I want make automate update when i start new ngrok instance

Twilio developer evangelist here. You can accomplish this via the Twilio CLI as well as with Python using Twilio Incoming Phone Numbers! That Python code would look something like this (replacing the variables with your own account SID, auth token, and the phone number SID you'd like to use which can be found in the Console or via the CLI):
import os
from twilio.rest import Client
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
incoming_phone_number = client \
.incoming_phone_numbers('PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
.update(voice_url='https://www.your-new-voice-url.com/example')
print(incoming_phone_number.friendly_name)
Let me know if this helps at all!

Related

Fetch all active fone numbers for a twilio account with python library

i am trying to get all active phone numbers for an account using twilio python library. i tried the proposed in this solution but is outdated. Thanks.
To get all your active phone numbers in your account, you can request the incoming phone numbers API and iterate through the results which will automatically page through the API. To make fewer requests, you can change the page size up to 1000.
import os
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
incoming_phone_numbers = client.incoming_phone_numbers.list(page_size=1000)
for phone_number in incoming_phone_numbers:
print(phone_number.sid)

can i automate this twilio verified phone numbers list from a python program

from twilio.rest import Client
import os
account_sid = 'ACXXXXXXXXXXXXXX'
auth_token = 'XXXXXXXXXXXXXXXXX'
client = Client(account_sid, auth_token)
mob = 'XXXXXXXXXX'
verify = client.verify.services('VAXXXXXXXXXXXXXXXXX')
verify.verifications.create(to=mob, channel='sms')
n = int(input('enter code: '))
result = verify.verification_checks.create(to=mob, code=n)
print(result.status)
after verifying the phone number i want to add that phone number to my twilio verified phone numbers lisI. I want to know if it is possible or not..
Yes you can do this by using the Twilio Voice API:
import os
from twilio.rest import Client
client = Client(account_sid, auth_token)
validation_request = client.validation_requests \
.create(
friendly_name='A friendly name',
phone_number='+1234567890'
)
print(validation_request.validation_code)
Taken and adapted from the Twilio documentation here.
Note:
This will create a new CallerID validation request within Twilio, which initiates a call to the phone number provided and listens for a validation code.
And:
Adding an Outgoing Caller ID via the API has the same result as verifying a number via the Twilio console.

Twilio Python: How to call Multiple calls by twilio

I Want To Call to Multiple phones by Twilio on python
I Just saw Twilio blog but nothing understood to me
this is my script
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
account_sid = "AC723c6c38e7c58a572ce011a652540a42"
auth_token = "REDACTED"
client = Client(account_sid, auth_token)
# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
call = client.calls.create(
)
print(call.sid)
So Can You Tell Me What To Do
Twilio developer evangelist here.
You should make an array of phone numbers to call and then loop through that array, calling calls.create method to make a call to each number in the array passed in as a parameter to calls.create.
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
account_sid = "AC723c6c38e7c58a572ce011a652540a42"
auth_token = "REDACTED"
client = Client(account_sid, auth_token)
# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
arr = ['INSERT-NUMBER-TO-CALL', 'INSERT-OTHER-NUMBER-TO-CALL'...]
for num in arr:
call = client.api.account.calls.create(
to=num,
from_='YOUR-TWILIO-NUMBER',
url = 'http://demo.twilio.com/docs/classic.mp3'
)
print(call.sid)
Alternatively, instead of url which would contain a link to a file you want to play on the phone, you could use twiml='<Response><Say>INSERT MESSAGE HERE</Say></Response>', to have a message played as well. You could use different Amazon Polly voices to customize the voice that speaks the message--more on that here.

Twilio Autopilot Python quickstart tutorial

I am trying to follow the following Twilio Autopilot tutorial https://www.twilio.com/docs/autopilot/quickstart/python?code-sample=code-create-your-first-assistant-with-autopilot-7&code-language=Python&code-sdk-version=6.x
I am trying to create my first assistant with autopilot and my own account_sid and auth_token.
# Download the helper library from
https://www.twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
assistant = client.autopilot \
.assistants \
.create(
friendly_name='Quickstart Assistant',
unique_name='quickstart-assistant'
)
print(assistant.sid)
However i receive the following error when i try execute the script.
Twilio developer evangelist here.
Did you by chance run this script more than once? The unique_name must be unique, so if you ran the script twice without changing that value, the second try would fail.
I tried running the code example you posted (with my own account credentials), and it worked the first time but failed the second time with the same exact error message you got (35002). Changing the unique_name value to quickstart-assistant-2, the script ran successfully again.
If you can log in to Twilio, you should be able to see the list of autopilot assistants you have created, which would tell you if you were able to create the assistant successfully on the first try.
Let me know if you have any additional questions or issues.

How to send customized reposne using Twilio API?

I am new to Twilio API and I am calling to a number and I want to play a customized message. Can anyone tell me how to do it? I know that I have to create a response file but I am not sure how to give that file in URL.
Here is my code.
# Download the library from twilio.com/docs/libraries
from twilio.rest import TwilioRestClient
# Get these credentials from http://twilio.com/user/account
account_sid = "xxxxxx"
auth_token = "yyyyyy"
client = TwilioRestClient(account_sid, auth_token)
# Make the call
call = client.calls.create(to="aaaaa", # Any phone number
from_="bbbbb", # Must be a valid Twilio number
url="??????")
print call.sid
What should I write in URL?
Thanks
Twilio developer evangelist here.
There are a couple of things you can do here. The url you enter in the outgoing call needs to respond with some XML (TwiML) when Twilio requests it.
If you want Twilio to play a message, you could write the following TwiML:
<Response>
<Say>Hello from my new Twilio app</Say>
</Response>
This can be a static file hosted anywhere. For example, you could use http://twimlbin.com/ to host it and then use the url given to you by that service.
Alternatively, you could create a webserver application using something like Python's Flask. There is a guide to this on the Twilio site here: https://www.twilio.com/docs/quickstart/python/twiml/say-response. You can then open your local development site to Twilio using a tool like ngrok and there's a good explanation of how to do that in this blog post: https://www.twilio.com/blog/2013/10/test-your-webhooks-locally-with-ngrok.html.
Hope that helps, let me know if there's anything more I can help you with.

Categories

Resources