Tago Run User´s Notification

Hello ! Is it possible to generate a push notification for all TagoRun users at the same time using just one action?

Hi, @leandro

Yes, it is. You can do it through analysis.
Instead of notification, the action will trigger an analysis.

Here is a basic snippet that you can use as a start point.
const { Analysis, Services, Utils } = require("@tago-io/sdk");

/**
 * The main function used by Tago to run the script.
 * It sends a notification to the account and another one linked to a dashboard.
 * Optional: You can set a dashboard_id using an environment variable
 * this will show a button on the notification to send the user directly to the dashboard
 */
async function sendNotification(context) {
  // reads the values from the environment variables and saves it in the variable env_vars
  const env_var = Utils.envToJson(context.environment);

  const notification = new Services({ token: env_var.account_token }).Notification;

  // In this variable, you type the title of the notification
  const title = 'Your title';

  // In this variable, you type the message that you will send on the notification
  const message = 'Your message';

  try {
    const service_response = await notification.send({
      message,
      title,
      ref_id: env_var.dashboard_id || undefined,
    });

    context.log(service_response);
  } catch (error) {
    context.log(error);
  }
}

module.exports = new Analysis(sendNotification);

// To run analysis on your machine (external)
// module.exports = new Analysis(sendNotification, { token: "YOUR-TOKEN" });

Let me know if you need any help.

Hello gclenz, when I run the suggested analysis the notifications do not occur on TagoRun and also do not occur on Dasboard. I only receive notifications when I am logged in to Tago. Is there any way to notify all my clientrs registered on TagoRun at the same time?

Hi @leandro,
The example from @gclenz is to send notification to your developer account, and not RUN users.

Please check TagoIO documentation on how to send to RUN users: https://docs.tago.io/en/articles/224
You can get the analysis template here: https://admin.tago.io/template/5d51de52171477001b203458

One thing that is not mentioned in the documentation is that you only need the parameter title and message in order to send a notification. All other parameters are optional.

Let’s test it, thanks. Any questions we will ask again