'use strict';

const Bot = require('node-telegram-bot-api');

const validator = require('validator');
const request = require('request-promise');
const symbols = require('log-symbols');

const bot = new Bot(process.env.TOKEN, {
    polling: true
});

bot.onText(/^\/start$/, (msg) => {
    bot.sendMessage(msg.chat.id, 'Just send me a url and I\'ll shorten it!');
});

bot.onText(/^\/shorten (.+)$/, (msg, match) => {
    let url = match[1];
    if (validator.isURL(url)) {
        request.get('http://tinyurl.com/api-create.php?url=' + url).then((r) => {
            bot.sendMessage(msg.chat.id, r);
            console.log(symbols.success, url, '-->', r);
        });
    } else {
        bot.sendMessage(msg.chat.id, 'Sorry, that\'s not a vaid URL :(');
        console.log(symbols.error, url);
    }
});

console.log(symbols.info, 'bot server started...');

@@ -486,12 +486,8 @@
 uest
-.get
 ('ht
@@ -499,42 +499,243 @@
 tiny
+-
 url.
-com/api-create.php?url=' + url
+info/api/v1/create', %7B%0A            method: 'GET',%0A            qs: %7B%0A                provider: 'tiny_url',%0A                apikey: process.env.APIKEY,%0A                format: 'text',%0A                url: url%0A            %7D%0A        %7D
 ).th

switch tinyurl provider