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);});
updates.js
client.addEventHandler((update) => {console.log("Received new Update");console.log(update);});
For new message updates, you can do this
asyncfunctioneventPrint(event:NewMessageEvent) {constmessage=event.message;// Checks if it's a private message (from user or bot)if (event.isPrivate){// prints sender idconsole.log(message.senderId);// read messageif (message.text =="hello"){constsender=awaitmessage.getSender();console.log("sender is",sender);awaitclient.sendMessage(sender,{ message:`hi your id is ${message.senderId}` }); } }}// adds an event handler for new messagesclient.addEventHandler(eventPrint,newNewMessage({}));
asyncfunctioneventPrint(event) {constmessage=event.message;// Checks if it's a private message (from user or bot)if (event.isPrivate){// prints sender idconsole.log(message.senderId);// read messageif (message.text =="hello"){constsender=awaitmessage.getSender();console.log("sender is",sender);awaitclient.sendMessage(sender,{ message:`hi your id is ${message.senderId}` }); } }}// adds an event handler for new messagesclient.addEventHandler(eventPrint,newNewMessage({}));