Updates (events)

All about events and updates

Defining events

Currently, there are only two types of events: Raw updates and NewMessage(more will come soon).

Defining an event is a fairly straightforward

For raw updates you can do this :

updates.ts
 client.addEventHandler((update: Api.TypeUpdate) => {
    console.log("Received new Update")
    console.log(update);
});

For new message updates, you can do this

async function eventPrint(event: NewMessageEvent) {
    const message = event.message;

    // Checks if it's a private message (from user or bot)
    if (event.isPrivate){
        // prints sender id
        console.log(message.senderId);
        // read message
        if (message.text == "hello"){
            const sender = await message.getSender();
            console.log("sender is",sender);
            await client.sendMessage(sender,{
                message:`hi your id is ${message.senderId}`
            });
        }
    }
}
// adds an event handler for new messages
client.addEventHandler(eventPrint, new NewMessage({}));

Last updated