【发布时间】:2018-10-07 17:37:36
【问题描述】:
我是用java构建的 电报机器人 这基本上得到了用户的名字 它可以是 1 或 10 甚至 40(我将其限制为 50)取决于你想放多少 现在这个机器人的目的是稍后当你完成你的特定用户时 你写一条消息发送给他们
现在一切正常,id 名称和消息都保存了 虽然 我如何将它发送给我只是作为私人消息插入的所有用户 如果可能的话……通过命令
我希望我足够理解
这是我的代码:
class Bot extends TelegramLongPollingBot {
public int counter = 0;
public ArrayList names = new ArrayList(50);
public SendMessage mainMessage = new SendMessage();
public String sgMsg = "";
public StringBuilder stringBuilder = new StringBuilder();
public String msg;
public void onUpdateReceived(Update update) {
String command = update.getMessage().getText();
SendMessage sysMsg = new SendMessage();
sysMsg.setChatId(update.getMessage().getChatId());
String firstCdletter;
firstCdletter = Character.toString(command.charAt(0));
if (command.equals("/start")) {
sysMsg.setText("Enter the user's id, to finish send: Ok");
try {
execute(sysMsg);
} catch (TelegramApiException e) {
e.printStackTrace();
}
counter = 0;
names.clear();
sgMsg = "";
}else if (firstCdletter.equals("@")) {
String user = command;
names.add(counter);
counter++;
}else if(command.equals("/ok")){
sysMsg.setText("Good, now write your message you want to deliver");
try {
execute(sysMsg);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}else if(command.equals("/done")){
msg = stringBuilder.toString();
}else{
sgMsg = update.getMessage().getText();
stringBuilder.append(sgMsg + " ");
}
}
感谢大家的宝贵时间和帮助
【问题讨论】:
标签: java bots telegram telegram-bot