1

i built by using java a telegram bot which basically get users's name it can be 1 or 10 or even 40 (i limited it to 50) depends on how much you want to put now the purpose of this bot is later on when you finish with your specific users you write a message to send them

now everything is work perfect the id names getting save as well the message although how do i send it to all the users i just insert as a private message if it even possible... by command

i hope i was understandable enough

thats my code:

    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 + " ");
    }

}

thank you all for your time and help

Carmel
  • 21
  • 1
  • 1
  • 5

1 Answers1

5

Unfortunately, you cannot send message via @username, the only identify you can use is UID (looks like 109780439).

And by the way, bot have to chat with that user before, or you will got an 400 Error.

Sean Wei
  • 7,433
  • 1
  • 19
  • 39
  • alright so lets say all those people get that bot lets say 20 people but i want that only 4 people will get the same message so i need to use their UID ? and if so where do i get that UID ? – Carmel Apr 26 '18 at 23:07
  • You can let users forward message from that user – Sean Wei Apr 27 '18 at 03:30
  • alright so how do i get their User id or atleast convert their username into User id so i could send them the message – Carmel Apr 27 '18 at 14:29
  • @Sean can't we integrate Telegram like whatsapp? There are number of sites that sends message to users on whatsapp? Like OYO does, when user book a room then OYO sends details on user's whatsapp. How to do it using Telegram? – Devendra Singh Dec 04 '18 at 07:25