Skip to content

Instantly share code, notes, and snippets.

@BenJam
Created January 14, 2011 11:32
Show Gist options
  • Save BenJam/779500 to your computer and use it in GitHub Desktop.
Save BenJam/779500 to your computer and use it in GitHub Desktop.
smsButton macro for TiddlyWiki/TiddlySpace
/***
|''Name:''|SMSButton|
|''Description:''|Ribbit-bases SMS of Tiddlers|
|''Author:''|BenJam|
|''CodeRepository:''|http://github.com/benjam/tiddlyspace-plugins|
|''Version:''|0.1|
|''Comments:''|Please make comments at http://github.com/benjam/tiddlyspace-plugins |
|''Requires:''|Ribbit plugin for authentication |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
Usage:
//{{{
<<smsButton name, sms, receiver, [sender]>>
name: the name of the button
sms: the SMS message to be sent
receiver: the reveiving number (format tel:[country code][number without leading 0])
sender (optional): any alpha/numerical number (remember: with great power comes great repsonsibility - Stan Lee)
//}}}
***/
//{{{
if(!version.extensions.smsButton){
version.extensions.smsButton = {installed:true};
(function($) {
var defaultSender = "TiddlySpace";
//TODO some more, better sanitisation
function sanatise(number){
var n = n.repalce(/[a-Z]/g,""); //remove an alpha
n = n.repalce(/\+/,""); //remove any leading +
return "tel:"+n;
}
config.macros.smsButton = {};
config.macros.smsButton.handler = function(place, macroName, params, wikifier, paramString, tiddler){
var prms = paramString.parseParams(null, null, true);
if(getParam(prms,"name")==null | getParam(prms,"sms")==null | getParam(prms,"revceiver")==null | getParam(prms,"sender")==null){
alert('Bah! You didn\'t supply the correct params');
return;
}else{
if(Ribbit.userId==null){
alert('Bah! There\'s no logged in Ribbit user serssion');
return;
}else{
//we have a logged in user and the right params now get to work!
createTiddlyButton(place, getParam(prms,"name"), "Click to send SMS", function(){
Ribbit.Messages().createSMS(function(r){
if (r.hasError){
alert('Bah! Couldn\'t send SMS');
}else{
return true;
}
},sanitise(receiver),getParam(prms,"sms"),getParam(prms,"sender") ? getParam(prms,"sender") : defaultSender);
});
}
}
};
})(jQuery);
}
//}}}
@BenJam
Copy link
Author

BenJam commented Jan 14, 2011

Note: untried, untested and unsafe. Requires Ribbit login plugin at: https://github.com/BenJam/tiddlywiki-plugins/tree/master/Login

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment