Skip to content

Messages

Listening

When you start the app, you can listen for incoming messages in the conversation using the run function.

src/index.ts
run(async (context: HandlerContext) => {
  // Get the message and the address from the sender
  const { content, sender } = context.message;
 
  // To reply, just call `reply` on the HandlerContext.
  await context.send(`gm`);
});

Message object

The message object contains the following

{
  id: string, // The id of the message
  content: {}, // The content of the message depending on the  type
  sender: User, // The user object of the sender
  sent: Date, // The timestamp of the message
  typeId: string; // The  type of the message (text, reply or reaction)
}

To learn more about the types, see types

Send message

App messages are messages that are sent when you send a reply to a message and are highlighted differently by the apps.

// Send a message
context.send("Your message.");
// Reply to the last message
context.reply("Your message.");
// Send a message to specific users
context.sendTo("Your message.", ["address1", "address2"]);
// React to the last message with an emoji
context.react("👍");

App messages are prevented from being sent to the app itself