aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/api/TelegramBotHook.java
blob: a502e846d390794d591ed515e5a572fcd5d92860 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.juick.api;

import com.pengrad.telegrambot.BotUtils;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.TelegramBotAdapter;
import com.pengrad.telegrambot.model.Update;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.logging.Logger;

/**
 * Created by vt on 12/05/16.
 */
public class TelegramBotHook {
    private static final Logger logger = Logger.getLogger(TelegramBotHook.class.getName());

    private String token;
    TelegramBot bot;


    public TelegramBotHook(String token) {
        this.token = token;
        bot  = TelegramBotAdapter.build(token);
        bot.setWebhook("https://api.juick.com/tlgmbtwbhk");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        StringBuilder sb = new StringBuilder();
        try (BufferedReader reader = request.getReader()) {
            Update update = BotUtils.parseUpdate(reader);
            logger.info("got telegram msg: " + update.message().toString());
        }
    }
}