![]() The complete Python code shown here can be found in Github.According to GSMA Intelligence, over 5 billion people worldwide have access to mobile phones. If you’ve got any feedback or would like some further clarification please send me an email using the details on the about page. I hope this has been interesting for you and you’ve been able to learn something! I’ve tested the code included here at the time of writing and, while quite basic, it does exactly what it needs to for sending messages. In a future post I’ll look at using the Retrieve SMS Responses API command to poll for replies from a user and basic branching conversation flow. However, it doesn’t really fulfil my aim of interactivity. The code above is great as a base for one-way communication from your code to a user. Token = auth ( "PutYour32CharClientKeyHereThanks", "ClientSecretHere" ) create_subscription ( token ) send_sms ( token, "+61400000000", "Hello sigsec readers!" ) ![]() ![]() Note that for authentication I don’t use the telstra_request method defined above - this particular endpoint requires payload data to be submitted in standard Form URL encoding (not JSON). See the documentation for this API call here, or my code as shown below. In order to start using the API services, we need to exchange this keypair for an authorisation token. You can view these keys on the My apps & keys page. You should have been automatically issued with a pair of API keys, under the application name “Free Trial APIs”. request ( method, url, json = body, headers = send_headers ) API keys and authentication update ( headers ) url = "" + endpoint return requests. Send_headers = 'Bearer ' + token if headers : # add any extra headers if desired Import requests def telstra_request ( endpoint, body = None, headers = None, *, token = None, method = 'POST' ): send_headers = if token : # if this is an authenticated request, add the token header The basic network code is as follows, edited for clarity: Fortunately, the protocol is extremely simple and we can use the requests module to handle most of it. As mentioned above, they provide a Python SDK you could just import but I like to understand what the code is doing and I’d like it to be consistent with the other APIs I’ve written, so I chose to implement it myself. Registering a mobile number subscription to deliver from, andīefore we send our first message, let’s quickly review the network code we’ll use.Exchanging your API key and secret key for a session token,.There’s three critical API calls involved in using Telstra to send SMS messages: They also provide an OpenAPI spec that you can import directly into Swagger a pre-built Postman image and API SDKs for a number of languages including Python. The Message API documentation is comprehensive and lays out exactly what you need to do to send text messages. It seems like a lot of the developer docs I’ve been dealing with lately have been written as an afterthought ( if they exist at all!), so it was very refreshing to see the effort and polish that has been put into the Telstra documentation. Take a couple of minutes to click around their developer website and marvel at just how nice it all is. You’ll need to verify you own the phone number that you provided, by entering a code they will send to you.Īnd that’s really it.Accept the terms and conditions, and then click ‘Create account’. A dialog will pop up, asking you for some information fill it in.Go to their developer site and click the ‘Register’ link in the header.Registering for their developer program was extremely simple. I’ve been interested in using text messages as an out-of-band communication medium for a while, and this was the perfect opportunity to explore the technology. ![]() In yet another article in the series of ‘playing with Python’, today we’re looking at sending text messages! In Australia, Telstra allows you to evaluate and develop with their API services for free, up to a limit of 1000 SMS per month and at most 100 in a single day.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |