Reputation: 1649
I have been asked to research in How to send a message to a telegram channel without a bot using JAVA. I am totally new to this Telegram API and all the examples I found uses a BOT. Could anyone please help me to start with a sample code with NO Bots please.
Thanks and really appreciate your views on this.
Upvotes: 0
Views: 8109
Reputation: 5552
You can give a try to tdlib/td
, a cross-platform library for building Telegram clients created by Telegram in C++. You can use it in Java via JNI (Java Native Interface). They provide a Java client example to help you get started and build your own client.
Their example provides the code for sending a message:
private static void sendMessage(long chatId, String message) {
// initialize reply markup just for testing
TdApi.InlineKeyboardButton[] row = {new TdApi.InlineKeyboardButton("https://telegram.org?1", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?2", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?3", new TdApi.InlineKeyboardButtonTypeUrl())};
TdApi.ReplyMarkup replyMarkup = new TdApi.ReplyMarkupInlineKeyboard(new TdApi.InlineKeyboardButton[][]{row, row, row});
TdApi.InputMessageContent content = new TdApi.InputMessageText(new TdApi.FormattedText(message, null), false, true);
client.send(new TdApi.SendMessage(chatId, 0, false, false, replyMarkup, content), defaultHandler);
}
Related resources:
Upvotes: 1
Reputation: 4352
I didn't work much by Java
But in general, you can use the following ways to send a message to the telegram:
Upvotes: 2