package com.hx.utils.application.util;

import org.json.JSONArray;
import org.json.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class TgUtils {
    private static final String BASE_URL = "https://api.telegram.org/bot7790802518:AAGmUCIdh-uogRuG4gElgxTG-yN7f0mGi7I/";
    private final OkHttpClient client = new OkHttpClient();

    public String getUpdatesSync() throws Throwable {
        String url = BASE_URL + "getUpdates?offset=-1&limit=10";
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful() && response.body() != null) {
            String jsonResponse = response.body().string();
            JSONObject jsonObject = new JSONObject(jsonResponse);
            JSONArray resultArray = jsonObject.getJSONArray("result");
            JSONObject data = new JSONObject(resultArray.get(0).toString());
            return data.toString();
        }
        return "";
    }

}
