i created app for forwarding sms to telegram group chat
app design
two inputs bottoken + chatid
i want app get chat dynamically from api link
https://api.telegram.org/bot<YourBOTToken>/getUpdates
when i click button (get chat id) then execute the link and get chat id from json result.
{
"update_id": 8393,
"message": {
"message_id": 3,
"from": {
"id": 7474,
"first_name": "AAA"
},
"chat": {
"id": <group_ID>,
"title": "<Group name>"
},
"date": 25497,
"new_chat_participant": {
"id": 71,
"first_name": "NAME",
"username": "YOUR_BOT_NAME"
}
}
}
i have made sending to telegram successfully i need this step before sending
this is my code for sending messages to telegram
public class RetrieveFeedTask extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... arg0) {
String a = arg0[0].toString();
String b = arg0[1].toString();
String c = arg0[2].toString();
String urlString = "https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s";
String apiToken = a;
String chatId = b;
String text = c;
//https://api.telegram.org/bot664321744:AAGimqEuidlzO84qMoY1-_C-1OsNWRQ8FyM/sendMessage?chat_id=-1001349137188&&text=Hello+World
urlString = String.format(urlString, apiToken, chatId, text);
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
//getting text, we can set it to any TextView
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String inputLine = "";
StringBuilder sb = new StringBuilder();
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
//You can set this String to any TextView
String response = sb.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
and i start send by this code from mainactivity
new RetrieveFeedTask().execute(apiToken, chatIds, text);
now i want to know how get chat id from telegram by bot token dynamically from application not manually
i searched all answers and topics related to my question and i didn’t found my answer clearly.
Progromatic World is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.