This snippet will get the most recent conversation and send a message in this conversation.

// This is a synchronous client, that will block until the response arrive (or until timeout)
TelegramClient client = Kotlogram.getDefaultClient(application, new ApiStorage());

// You can start making requests
try {
    TLAbsDialogs tlAbsDialogs = client.messagesGetDialogs(0, 0, new TLInputPeerEmpty(), 1);
    TLAbsInputPeer inputPeer = getInputPeer(tlAbsDialogs);

    TLAbsUpdates tlAbsUpdates = client.messagesSendMessage(inputPeer, "Sent from Kotlogram :)", Math.abs(new Random().nextLong()));

    // tlAbsUpdates contains the id and date of the message in a TLUpdateShortSentMessage
} catch (RpcErrorException | IOException e) {
} finally {
    client.close(); // Important, do not forget this, or your process won't finish



When sending a message, you need to specify a random long, if you try to send two successive message with the same id in a short amount of time, it's my understanding that it'll fail.

Did this page help you?