[Kde-pim] Future of SMS messaging through Kontact
Stephen Kelly
steveire at gmail.com
Wed Sep 12 01:17:11 BST 2007
Hi. First off, thanks for developing kontact. I've found it to be an
excellent application, and now use it and related programs for all aspects
of addressbook management, mail, mailing lists and rss feed reading.
I'm a new and inexperienced developer and I want to start working on better
SMS messaging through kontact.
Currently kontact/kaddressbook offer to pass a number and a message file to
a shell command. That's fine, but it does not offer any feedback of whether
the message was successfully sent or any other info.
I'd like to fix that for kde4, but I'm quite inexperienced with development.
I had a kde4 svn checkout a few months ago, but I've not kept it up to
date. I'll probably install that SDK mentioned on k-c-d and put this
together then if possible (and if someone else hasn't already done it).
Before then I'd like to get an idea of what'll be involved in making this
work.
My intention is to use kross to connect to different SMS message sending
providers. People writing the kross scripts would specify what provider it
is for, a login method, a sendMessage method, a logout method and any other
helper methods. I've only read about kross, and I don't know how it really
works, but I'm assuming that's possible.
Here's what the config dialog might look like:
http://img20.imageshack.us/my.php?image=kontactsmsmockup2oo9.png
It allows the user to specify a service to log into to send messages through
and would allow for download or creation of new scripts.
Also I'd like to have something like the following
under View -> Sent SMS messages... or something:
http://img411.imageshack.us/my.php?image=kontactsmsmockup1ls9.png
I shows recently sent messages, the recipient, and whether it was
successfully sent.
I currently use the attached script to send messages though kontact, and I'm
sure other classes similar to MeteorHandler could be written very quickly.
I could write handlers for the other two providers in Ireland - O2 and
Vodafone. I'd expect to connect when attempting to send the first message
in a session, and then log out when kontact closes.
How much sense does this make? Is this what kross is suited to? This also
seems to be a candidate for a plasmoid, so I'll probably look into that
too.
Also, I'd like to know the current state and plans for kaddressbook so that
I'm not duplicating work, and I can work with whoever is doing this.
Thanks and regards,
Stephen
----[ /home/stephen/metsend.py ]
| #!/usr/bin/env python
| #-*- coding: utf-8 -*-
|
| from optparse import OptionParser
| import urllib2, urllib, cookielib
|
| class MeteorHandler:
| """
| This class handles sending messages through mymeteor.ie
| """
| def __init__(self):
| self.baseURL = "https://www.mymeteor.ie/mymeteor"
| self.systemURL = self.baseURL + "/system"
| self.controllerURL = self.systemURL + "/controllers/controller.cfc"
| self.smsURL = self.systemURL + "/view/sms.cfm"
| self.smsNumber = "08"
| cj = cookielib.CookieJar()
| self.opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1),
| urllib2.HTTPSHandler(debuglevel=1),
| urllib2.HTTPCookieProcessor(cj))
|
| def _open(self, *args):
| """
| Conveniece function to call self.opener.open()
| """
| response = self.opener.open(*args)
| return response
|
| def controller(self, params):
| """
| Most requests are sent to the controller URL. This is a
| convenience function to POST params to the url.
| """
|
| encodedParams = urllib.urlencode(params)
| response = self._open(self.controllerURL, encodedParams)
| return response
|
| def login(self, number, pin):
| """
| Log in to mymeteor.ie.
| Returns response object or False if failure.
| """
| params = {"method": "logIn",
| "msisdn": number,
| "pin": pin,
| "returnTo": "/mymeteor/login.cfm"}
|
| encParams = urllib.urlencode(params)
| response = self._open(self.controllerURL, encParams)
| if self._isLoggedIn():
| return response
| else:
| return False
|
| def _isLoggedIn(self):
| """
| Run a test to see if we are currently logged in.
| """
| # If we are not logged in, navigating to
| # home.cfm will redirect to login.cfm
| response = self._open(self.systemURL + "/view/home.cfm")
| if response.url == self.baseURL + '/login.cfm':
| return False
| elif response.url == self.systemURL + "/view/home.cfm":
| return True
|
| def logout(self):
| """
| Log out.
| """
| if self._isLoggedIn():
| response = self._open(self.baseURL + "/logout.cfm?logout=true")
| return True
|
| def sendMessage(self, message, number):
| """
| Send message to number.
| """
| params = {"method": "SMS",
| "sms_text": message,
| "msisdn": number,
| "returnTo": "`/mymeteor/system/view/sms.cfm",
| "formName": "smsForm",
| "clicked": "1",
| "action": "Send SMS"}
|
| response = self.controller(params)
|
| if response.url == self.systemURL + '/view/smssent.cfm':
| return True
| else:
| return False
|
|
| if __name__ == "__main__":
|
| parser = OptionParser()
| parser.add_option("-a", "--account", help="An account (phone number) to
| send the message from.") parser.add_option("-p", "--pin", help="A pin or
| password to log in to your account.") parser.add_option("-n",
| "--number", help="A single phone number to send the message to.")
| parser.add_option("-m", "--message", help="The text of the message
| surrounded in \". Use either -m or -f, but not both.")
| parser.add_option("-f", "--file", help="A file containing the text of
| the message. Use either -m or -f, but not both.")
|
| (options, args) = parser.parse_args()
|
| messageText = ""
| if options.message and options.file:
| parser.error("Error. Use either --message or --file, but not both.")
| if options.message:
| messageText = options.message
| if options.file:
| messageFile = open(options.file, "r")
| messageText = messageFile.read()
|
| if messageText:
| handler = MeteorHandler()
| if handler.login(options.account, options.pin):
| messageSent = handler.sendMessage(messageText, options.number)
| if messageSent:
| print "MESSAGE SENT"
| else:
| print "MESSAGE SENDING FAILED"
| handler.logout()
`----
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list