klionwii.blogg.se

Send sms python
Send sms python









Thus we use tonumber and fromnumber instead when running the send command.

#Send sms python update#

In test_main.py, update the test_send_success() function, and add in the following tests, replacing your_number with your verified phone number, and your_twilio_number with your Twilio phone number:Īs you may have noticed, in the send() function, you defined the parameters as toNumber and fromNumber, but Typer automatically turns these into lowercase when running the app. Now that you have updated the command, you can also update its related tests. Test the endpoint for sending SMS messages

send sms python

You then just simply print the message sent through the Twilio SMS API. Similar to send_sms.py, you must use the number you bought from Twilio, and the number you used for verifying your Twilio account. Once you get past the checks for errors, you then create the Twilio Client, and send a message with the values passed into the query parameters. There are loads more edge cases to tackle, but for our use case, these will do. In the case these edge cases are met, you simply exit the program. Here you just check for some simple edge cases that would make the application not work as expected. You'll also see that you have some raise typer.Exit() statements. In the send command, you added three required option parameters, which are the variables you'll be needing for sending your SMS messages. Print("Message Body: " + clientMessage.body) If (account_sid = None and auth_token = None):Įrror_detail = "Missing values for TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN\n" + "SID: " + account_sid + "\n" + "Token: " + auth_tokenĮrror_detail = "Missing value for TWILIO_ACCOUNT_SID\n" + "SID: " + account_sidĮrror_detail = "Missing value for TWILIO_AUTH_TOKEN\n" + "Token: " + auth_token

send sms python

# in the case this happens and you already have your. Print("Phone numbers must start with a '+'")Īccount_sid = os.getenv("TWILIO_ACCOUNT_SID")Īuth_token = os.getenv("TWILIO_AUTH_TOKEN") If (toNumber != "+" or fromNumber != "+"):

send sms python

Print("Missing required values for required arguments") If (toNumber = None or toNumber = "" or fromNumber = None or fromNumber = "" or message = None or message = ""): Send(toNumber: str = typer.Option(.), fromNumber: str = typer.Option(.), message: str = typer.Option(.)):









Send sms python