         return msg.reply "Hmmm. I'm not sure if the tweet posted. Check the account: http://twitter.com/#{username}"
 
   robot.respond /untweet\@([^\s]+)\s(.*)/i, (msg) ->
-    username = msg.match[1]
-    tweet_id = msg.match[2]
+    username        = msg.match[1]
+    tweet_url_or_id = msg.match[2]
+    tweet_id        = extract_tweet_id(tweet_url_or_id)
+    unless tweet_id
+      msg.reply "Sorry, '#{tweet_url_or_id}' doesn't contain a valid id. Make sure it's a valid tweet URL or ID."
+      return
 
     authenticated_twit(username).post "statuses/destroy/#{tweet_id}", {}, (err, reply) ->
       if err

    consumer_secret: config.consumer_secret
    access_token: config.accounts[username].access_token
    access_token_secret: config.accounts[username].access_token_secret

unless config.consumer_key
  console.log "Please set the HUBOT_TWITTER_CONSUMER_KEY environment variable."

#
# Commands:
#   hubot tweet@<screen_name> <update> - posts <update> to Twitter as <screen_name>
#   hubot untweet@<screen_name> <tweet_url_or_id> - deletes <tweet_url_or_id> from Twitter
#   hubot retweet@<screen_name> <tweet_url_or_id> - <screen_name> retweets <tweet_url_or_id>. Alias: rt@<screen_name>
#
# Dependencies:
#   "twit": "1.1.8"
