Je suis novice et j'ai écrit le code de mon TelegramBot dans Eclipse. Cela fonctionne bien, mais je voudrais savoir comment je peux le faire fonctionner sans que je lance l'application Java . Je suppose que je devrais utiliser le serveur pour cela. MerciComment faire fonctionner TelegramBot en permanence, sans démarrer manuellement mon programme Java tout le temps?
Modifier: Ajout du code Java
import java.time.LocalDateTime;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;
public class MyFirstBot extends TelegramLongPollingBot{
@Override
public String getBotUsername() {
// TODO Auto-generated method stub
return "TheBot Version0.01";
}
@Override
public void onUpdateReceived(Update update) {
// TODO Auto-generated method stub
SendMessage message = new SendMessage()
.setChatId(update.getMessage().getChatId());
if(update.hasMessage() && update.getMessage().isCommand()){
try{
switch(update.getMessage().getText()){ //reads command
case("/hello"):
message.setText("Hi there!");
sendMessage(message); //says hello
break;
case("/date"):
message.setText(LocalDateTime.now().toString());
sendMessage(message); //tells time and date
break;
default:
message.setText("Invalid Value");
sendMessage(message);} //in case no such command exists
}
catch(TelegramApiException e){
e.printStackTrace();
}
}
}
@Override
public String getBotToken() {
// TODO Auto-generated method stub
return "xxx";
}
}
donc montrer le code –
@JacekCz fait ... – TeamBeam
vous devriez inclure probablement pas jeton bot, puisque celui qui a, peut contrôler votre bot – Cargeh