Skip to content

Instantly share code, notes, and snippets.

@ibrahimrajabli
Forked from dds861/SendMessage.java
Created January 24, 2021 08:48
Show Gist options
  • Select an option

  • Save ibrahimrajabli/5af34cfc5a80ff03c74ee8eb38128533 to your computer and use it in GitHub Desktop.

Select an option

Save ibrahimrajabli/5af34cfc5a80ff03c74ee8eb38128533 to your computer and use it in GitHub Desktop.
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class SendMessage {
public static void sendToTelegram() {
String urlString = "https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s";
//Add Telegram token (given Token is fake)
String apiToken = "239287362:tyhERhehjr-dfg345gDFGWERWg245gwdfge";
//Add chatId (given chatId is fake)
String chatId = "-210987654";
String 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());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment