Back in September, BT previewed it’s .NET Web21C SDK, a set of libraries for the Microsoft .NET framework which allows you to do ultra cool things like make phone calls to any number in the world, send text messages (SMS), get someone’s location based no cell data to name a few.
A few weeks ago, more languages were been added and users interested in toying around but not necessarily in using the .NET framework can now have a play. Supported languages include Java, Python and PHP. In this entry I intend to show you how to quickly get started with using the Python SDK.
You should first download the sdk from their website and install as per the instructions on there. It is a standard python package so
sudo python setup.py install
will work just fine, however access to their services is regulated using X509 certificates and as such you ‘ll need to follow the instructions in the README file on how to generate and where to place the certs. Instructions are quite straightforward and it is only a one off task so you might as well bite that bullet now.
Now launch your python interpreter and type the following.
phone call
import btsdk
phonebox = btsdk.services.ThirdPartyCall()
callId = phonebox.makeCall('tel:447900000000', 'tel:447700000000') # pass both telephone numbers to connect the caller with the callee
Your phones should ring shortly after this. The function ThirdPartyCall#makeCall() returns a callId which you can see if you do this.
print callId
call:6ab682cb695c3317e82dbaec44a8ca92
the callId returned by the server can be used to poll the server for call status
phonebox.getCallInformation(callId)
{'status': 'CallTerminated', 'duration': 26, 'starttime': (2007, 3, 29, 17, 23, 53, 0, 0, 0), 'terminationCause': 'CallingPartyHungUp'}
and also to terminate the call
phonebox.endCall(callId)
u'OK'
This thing also supports conferencing, see the
btsdk.services.Conferencing
module for how to setup 3 ways between the pizza guy, the talking clock and your best mate’s ex-girlfriend. [Disclaimer, I haven’t done this personally and am not liable for any inconvenience caused by my suggestion]
send text messages (SMS)
import btsdk
from datetime import datetime
now = "The time now is %s" % datetime.now().strftime("%H:%M:%S on %Y-%m-%d")
thumbbox = btsdk.services.Messaging()
messageId = thumbbox.sendMessage(['tel:447900000000'], 'your-cellphone-number' , now)
print messageId
u'ef3c2280be22202caaf56820fee6d31aat'
The first parameter is a list of telephone numbers you want the message to be delivered to, in this case, just the one.
The second parameter is what gets shown to the recipient as being the origin of the text, you could put “WilliamPitt” if sending a text message to Tony blair (but I strongly advice against it - Pitt though often confused as a Tory was in fact against partisan politics and Tony is, well, a very powerful man).
Oh, also do be careful when typing, I mistyped one of the digits in my cell phone and ended up sending a somewhat weird message to a poor guy I don’t know. Sorry mate.
Back to our little tutorial. The messageId can be used as follows
thumbbox.getMessageDeliveryStatuses(messageId)
[{'destinationUri': u'tel:447918196695', 'status': 'Delivered'}]
The messaging API also has a class
btsdk.services.InboundSMS
which allows both sending a receiving of text messages, if you wanted to build a two way communication channel for instance. Recently I began to get automated text messages at 8am from my doctor on mornings when I had an appointment. It meant I stopped forgetting to go see the lovely Dr Heath. Nifty huh?
The list of potential applications one could build which used these services are limitless, let your imagination roam wild and see what you come up with but whatever you do, don’t replace the comments system on your blog with an automatic dialler. You might get random readers (sorry I meant lovely internet people) calling you to correct your spelling mistakes at 3:00AM - unless you don’t mind that kind of thing ofcourse.
The Location API
btsdk.services.Location
btsdk.services.LocationPermission
btsdk.services.LocationProfile
as the name suggests allows you to perform all kinds of magic trick based on Cell of origin data. Celebrity stalking being one of them. I ‘ll be posting some samples of how to use it on here shortly
but if you are curious and can’t wait, then why not try to find out exactly where your other half is right now.*
*Limits:
The Web21C project is still in beta and so there are restriction on usage.
All the services are provided free of charge at the moment, but this might change I expect.
Phone calls get terminated after 2mins to prevent you calling the speaking clock in Perth and leaving the phone hanging (Unless you are in Perth, in which case why would you care what time it is?)
You have to ask for the cellphone owner’s permission before you can locate them since you aren’t Big Brother
There is a limit on the number of API calls you can make each day so it definitely doesn’t make sense to put something like this
thumbbox.getMessageDeliveryStatuses(messageId)
on a cron job.
Please leave comments if you are thinking of or do build something using the python sdk or have technical questions related to the API. Happy hacking.