package net.vexelon.currencybg.srv.reports;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pengrad.telegrambot.Callback;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.TelegramBotAdapter;
import com.pengrad.telegrambot.request.SendDocument;
import com.pengrad.telegrambot.response.SendResponse;

import net.vexelon.currencybg.srv.GlobalConfig;

public class TelegramReporter extends AbstractReporter {

	private static final Logger log = LoggerFactory.getLogger(TelegramReporter.class);

	public TelegramReporter(String name) {
		super(name);
	}

	public TelegramReporter() {
		this("Telegram");
	}

	@Override
	public void send() throws IOException {

		TelegramBot bot = TelegramBotAdapter
				.build(/* "264497873:AAGjShbt3-CJkuSHJLwyMccTbvh-0PxNZ68" */GlobalConfig.INSTANCE.getBotToken());

		bot.execute(new SendDocument(/* "@ceco88" */GlobalConfig.INSTANCE.getBotChannel(),
				buffer.toString().getBytes("UTF-8")), new Callback<SendDocument, SendResponse>() {
					@Override
					public void onFailure(SendDocument request, IOException e) {
						log.error("Telegram SendDocument failed!", e);
					};

					@Override
					public void onResponse(SendDocument request, SendResponse response) {
						// do nothing
					};
				});
	}

}

@@ -725,17 +725,126 @@
 ption %7B%0A
-%0A
+%09%09if (!GlobalConfig.INSTANCE.getBotToken().isEmpty() && !GlobalConfig.INSTANCE.getBotChannel().isEmpty()) %7B%0A%0A%09
 %09%09Telegr
@@ -877,73 +877,15 @@
 pter
-%0A%09%09%09%09
 .build(
-/* %22264497873:AAGjShbt3-CJkuSHJLwyMccTbvh-0PxNZ68%22 */
 Glob
@@ -919,16 +919,17 @@
 en());%0A%0A
+%09
 %09%09bot.ex
@@ -1005,16 +1005,17 @@
 nnel(),%0A
+%09
 %09%09%09%09buff
@@ -1094,24 +1094,25 @@
 e%3E() %7B%0A%09%09%09%09%09
+%09
 @Override%0A%09%09
@@ -1101,32 +1101,33 @@
 %09%09%09%09%09%09@Override%0A
+%09
 %09%09%09%09%09public void
@@ -1182,16 +1182,17 @@
 %7B%0A%09%09%09%09%09%09
+%09
 log.erro
@@ -1239,12 +1239,14 @@
 %09%09%09%09
+%09
 %7D;%0A%0A
+%09
 %09%09%09%09
@@ -1257,24 +1257,25 @@
 erride%0A%09%09%09%09%09
+%09
 public void 
@@ -1338,16 +1338,17 @@
 %7B%0A%09%09%09%09%09%09
+%09
 // do no
@@ -1353,16 +1353,17 @@
 nothing%0A
+%09
 %09%09%09%09%09%7D;%0A
@@ -1370,12 +1370,17 @@
 %09%09%09%09
+%09
 %7D);%0A
+%09%09%7D%0A
 %09%7D%0A%0A

Send Telegram msg only if channel and bot properties are set