Created
April 24, 2013 13:40
-
-
Save arya-s/5452189 to your computer and use it in GitHub Desktop.
Using google's URL shortener.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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