Closed nickolson77 closed 6 years ago
Maybe you can try to configure a RequestConfig with the settings of your proxy and provide it in the BotOptions? https://github.com/rubenlagus/TelegramBots/blob/master/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultBotOptions.java#L69
Thanks for reply, it works! Could you review my code. Is this "template" good for starting implementing telegram bot? (plan to increase features) Method "sendMessage(sendMessage)" is deprecated. (@Deprecated public final Message sendMessage(SendMessage p1) { }) Are there alternatives ?
public class SimpleBot extends TelegramLongPollingBot {
private SimpleBot(DefaultBotOptions options) {
super(options);
}
public static void main(String[] args) {
HttpHost proxy = new HttpHost("10.10.10.2", 3008);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
DefaultBotOptions options = new DefaultBotOptions();
options.setRequestConfig(config);
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new SimpleBot(options));
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
@Override
public String getBotUsername() {
return "NAME_bot";
}
@Override
public String getBotToken() {
return "*******";
}
@Override
public void onUpdateReceived(Update update) {
Message message = update.getMessage();
if (message != null && message.hasText()) {
if (message.getText().equals("/help")){
sendMsg(message, "Hi, I'm bot");
}
}
}
private void sendMsg(Message message, String text) {
SendMessage sendMessage = new SendMessage();
sendMessage.enableMarkdown(true);
sendMessage.setChatId(message.getChatId().toString());
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setText(text);
try {
sendMessage(sendMessage);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
Method "sendMessage(sendMessage)" is deprecated. (@deprecated public final Message sendMessage(SendMessage p1) { }) Are there alternatives ?
Alternatives are #execute
Alternatives are #execute
Sorry, not clear for me =) What do you mean saying #execute ?
@nickolson77 The new method is called execute
instead of sendMessage
.
Ok, thanks =) It works!
ps Now I'm trying to implement following for my bot and can't find any examples: 1) User subscribe to my bot 2) Bot send message to all subscribed users
Could you help me?
See https://github.com/rubenlagus/TelegramBots/wiki/Getting-Started.
Check for /start
message.
For your second question just send a message to all your users via chatIDs (throttle sending to ~30msg/second!).
Hi, I'm using below code and got error. Maybe problem in proxy settings?