Skip to content

Instantly share code, notes, and snippets.

@arya-s
Created April 24, 2013 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arya-s/5452189 to your computer and use it in GitHub Desktop.
Save arya-s/5452189 to your computer and use it in GitHub Desktop.
Using google's URL shortener.
function addLink(msg, from, to){
var url = msg;
googleapis.discover('urlshortener', 'v1').execute(function(err, client){
client.urlshortener.newRequest('urlshortener.url.insert', { resource: {longUrl: url}}).execute(function(err, result){
var shortUrl = 'Cannot shorten '+url;
if(err){
console.log('Shortening error: ',err);
} else {
shortUrl = result.id;
}
addToLinks(shortUrl, from);
bot.say(to, 'I might have added '+url+' to recommendations.');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment