Sometimes you might want to receive an copy of messages when they are sent to a specific user or conversation. For example, as a platform admin you might want to be notified if a customer sends a message to one of their suppliers, or replies in a specific chat.

The best way to do this depends on the details of what you want to track:

  • if you want to receive an email copy of all messages to a user, you can add an extra email address to the user's data
  • if you want to receive an email copy of all messages in a conversation, you can add a hidden admin user to that conversation
  • for more specific requirements, you can use webhooks and filter on messages sent

This guide will walk you through these methods in turn.

Add an extra email address to a user

TalkJS supports adding multiple email addresses to a user. You can use this to add an admin email address as well as the user's own email address:

const customer = new Talk.User({
  id: "exampleCustomer",
  name: "Sebastian",
  email: ["sebastian@example.com", "admin@example.com"], // extra admin address
  role: "default",
  photoUrl: "https://talkjs.com/images/avatar-2.jpg",
  });

The admin user will then also receive any emails that the user receives.

Add a hidden user

If you want to receive an email when new messages are added to a specific conversation, you can add a hidden user.

You can do this by adding a hidden custom property to your users, and then editing your theme to not display users with hidden: true. For more details on how to do this, see our tutorial on How to add a hidden user to a TalkJS conversation.

You can then add an admin user with hidden: true to the conversation:

const customer = new Talk.User({
  id: "exampleCustomer",
  name: "Sebastian",
  email: "admin@example.com"
  role: "default",
  photoUrl: "https://talkjs.com/images/avatar-2.jpg",
  custom: {
    "hidden":"true"
  }, // "hidden" custom field
  });

New messages will go to their email address.

Use webhooks to track sent messages

If you need a more custom way of tracking messages, you can use webhooks. Webhooks let you listen for specific events, such as new sent messages. You can then choose to filter these based on a specific user, conversation, or any other property of the event.

Webhooks are server-side only, so you’ll need a backend web server. To enable webhooks, go to the Settings tab of the TalkJS dashboard. In the Webhooks section, add the Webhook URL of the endpoint where you want to receive webhook events, and select the types of events you want to listen for:

For a tutorial that walks you through an example of how to set up and use webhooks, see How to mark a conversation as answered.

You’ve successfully subscribed to TalkJS
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Your link has expired
Success! Check your email for magic link to sign-in.