Notification Automation (Email + SMS + Telegram) via Triggers

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Setting Up Notification Automation (Email + SMS + Telegram) via Triggers

An automated notification system sends messages to users on trigger events through multiple channels. A unified notification service receives events from the application and distributes them across channels based on user preferences.

Notification Service Architecture

// notification.service.ts
interface NotificationRequest {
  userId: string;
  type: NotificationType;
  data: Record<string, unknown>;
  channels?: Channel[];  // if not specified — by user settings
  priority?: 'high' | 'normal' | 'low';
}

type NotificationType =
  | 'order.placed'
  | 'order.shipped'
  | 'payment.failed'
  | 'password.reset'
  | 'promo.discount';

class NotificationService {
  async send(request: NotificationRequest): Promise<void> {
    const prefs = await this.userPrefsRepo.findByUserId(request.userId);
    const channels = request.channels ?? this.resolveChannels(request.type, prefs);

    await Promise.allSettled(
      channels.map(channel => this.sendViaChannel(channel, request, prefs))
    );
  }

  private resolveChannels(type: NotificationType, prefs: UserPrefs): Channel[] {
    const channelMap: Record<NotificationType, Channel[]> = {
      'order.placed': ['email', 'telegram'],
      'order.shipped': ['email', 'sms', 'telegram'],
      'payment.failed': ['email', 'sms'],      // critical — all channels
      'password.reset': ['email'],              // email only
      'promo.discount': prefs.marketingChannels // user choice
    };
    return channelMap[type] ?? ['email'];
  }
}

Email via Resend

import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);

async function sendEmailNotification(
  user: User,
  type: NotificationType,
  data: Record<string, unknown>
) {
  const template = emailTemplates[type];

  await resend.emails.send({
    from: '[email protected]',
    to: user.email,
    subject: template.subject(data),
    react: template.component({ user, ...data })
  });
}

// Template for order.shipped
const orderShippedTemplate = {
  subject: (data) => `Your order #${data.orderId} has been shipped`,
  component: ({ user, orderId, trackingNumber, estimatedDelivery }) => (
    <OrderShippedEmail
      name={user.firstName}
      orderId={orderId}
      trackingNumber={trackingNumber}
      trackingUrl={`https://example.com/track/${trackingNumber}`}
      estimatedDelivery={estimatedDelivery}
    />
  )
};

SMS via Twilio

import twilio from 'twilio';
const client = twilio(process.env.TWILIO_SID, process.env.TWILIO_TOKEN);

async function sendSmsNotification(
  user: User,
  type: NotificationType,
  data: Record<string, unknown>
) {
  if (!user.phone || !user.phoneVerified) return;

  const templates: Record<NotificationType, (data: Record<string, unknown>) => string> = {
    'order.shipped': (d) =>
      `Order #${d.orderId} shipped. Track: ${d.trackingNumber}. Expect by ${d.date}`,
    'payment.failed': (d) =>
      `Payment for order #${d.orderId} failed. Update card: ${d.retryUrl}`
  };

  const text = templates[type]?.(data);
  if (!text) return;

  await client.messages.create({
    to: user.phone,
    from: process.env.TWILIO_PHONE,
    body: text
  });
}

Telegram via Bot API

import TelegramBot from 'node-telegram-bot-api';
const bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN);

async function sendTelegramNotification(
  user: User,
  type: NotificationType,
  data: Record<string, unknown>
) {
  if (!user.telegramChatId) return;

  const messages: Record<string, (d: Record<string, unknown>) => string> = {
    'order.shipped':
      (d) => `📦 *Order #${d.orderId} shipped*\n\nTracking: \`${d.trackingNumber}\`\nExpected: ${d.date}`,
    'payment.failed':
      (d) => `⚠️ *Payment Error*\n\nOrder #${d.orderId} not paid. [Retry](${d.retryUrl})`
  };

  const text = messages[type]?.(data);
  if (!text) return;

  await bot.sendMessage(user.telegramChatId, text, {
    parse_mode: 'Markdown',
    disable_web_page_preview: true
  });
}

// Telegram account binding by user
bot.onText(/\/start (.+)/, async (msg, match) => {
  const linkToken = match[1];
  const userId = await verifyLinkToken(linkToken);

  if (userId) {
    await userRepo.updateTelegramChatId(userId, msg.chat.id.toString());
    bot.sendMessage(msg.chat.id, '✅ Telegram connected! You will receive notifications.');
  }
});

Preference Management

// Table user_notification_prefs
interface UserNotificationPrefs {
  userId: string;
  emailEnabled: boolean;
  smsEnabled: boolean;
  telegramEnabled: boolean;
  marketingEmailEnabled: boolean;
  marketingSmsEnabled: boolean;
  quietHoursStart: string;  // '22:00'
  quietHoursEnd: string;    // '08:00'
  timezone: string;         // 'Europe/Moscow'
}

Retry and Queue

// Notifications via Bull Queue with retry
const notificationQueue = new Bull('notifications', { redis: redisConfig });

notificationQueue.process(async (job) => {
  const { userId, type, data } = job.data;
  await notificationService.send({ userId, type, data });
});

// Add with delay for non-urgent
await notificationQueue.add(
  { userId, type: 'promo.discount', data },
  {
    delay: 5 * 60 * 1000,  // 5 minute delay
    attempts: 3,
    backoff: { type: 'exponential', delay: 2000 }
  }
);

Timeline

Email + SMS + Telegram with preference management and queue — 1–2 weeks.