Skip to main content

Notification Service

Aventian provides a pub/sub-based Notification Service that abstracts away notification delivery complexities, making integration simple and consistent across all products.

Currently supported:

  • Email notifications (via SendGrid)

Architecture

The Notification Service is built using Google Pub/Sub and Cloud Functions, ensuring scalability and reliability.

Usage Guide

The Notification Service expects a JSON payload published to a Pub/Sub topic. Supported notification combinations:

  • Email Only

1. Email Notification Only

{
"type": ["email"],
"product_id": 1,
"email_contents": {
"recipient": ["user@domain.com"],
"template_id": "d-403d76b8a1554dbf957363949718c447",
"dynamic_template_data": {
"userName": "John Doe",
"link": "https://qa.aventian.com"
}
}
}

Field Validity

FieldValid ValuesRequired For
type["email"]All requests
product_idMust match valid product in your systemAll requests
email_contentsObject with recipient + template fieldsWhen type includes email
email_contents.recipientArray of valid emails (e.g., ["a@b.com"])Email only
in_app_contentsObject with body + optional fieldsWhen type includes in-app
in_app_contents.bodyNon-empty string (e.g., "Hello user!")In-app only

Custom Email Templates

Aventian allows teams to create and manage custom email templates for product notifications.

  • Templates are managed in the Sendgrid portal.
  • Once created, templates can be referenced via their template_id in the email_contents payload.
  • For access to the Sendgrid portal or to request template creation permissions, please reach out to the Aventian team.

Pub/Sub Authentication

  • To publish to Pub/Sub, authentication is required.
  • The product team must ask Aventian team for service account key to configure Pub/Sub client libraries.
  • This key should be kept securely in your product’s secret manager or environment variables.

Publishing Example

Node.js

import { PubSub } from "@google-cloud/pubsub";

const pubSubClient = new PubSub();

async function publishMessage(topicNameOrId: string, data: object) {
const dataBuffer = Buffer.from(JSON.stringify(data));
const topic = pubSubClient.topic(topicNameOrId);

try {
const messageId = await topic.publishMessage({ data: dataBuffer });
console.log(`Message ${messageId} published.`);
} catch (error) {
console.error(`Error publishing: ${(error as Error).message}`);
}
}

// Example usage: Email only
const payload = {
type: ["email"],
product_id: 1,
email_contents: {
recipient: ["user@test.com"],
template_id: "d-403d76b8a1554dbf957363949718c447"
}
};

publishMessage("notification-service-qa", payload);

Python

from google.cloud import pubsub_v1
import json

# Create a publisher client
publisher = pubsub_v1.PublisherClient()

def publish_message(topic_name_or_id: str, data: dict):
# Convert data dict to JSON string and then to bytes
data_bytes = json.dumps(data).encode("utf-8")

try:
# Publish the message
future = publisher.publish(topic_name_or_id, data=data_bytes)
message_id = future.result() # Block until the publish succeeds
print(f"Message {message_id} published.")
except Exception as e:
print(f"Error publishing: {e}")

# Example usage: Email only
payload = {
"type": ["email"],
"product_id": 1,
"email_contents": {
"recipient": ["user@test.com"],
"template_id": "d-403d76b8a1554dbf957363949718c447"
}
}

topic_path = "projects/aventian/topics/notification-service-qa"

publish_message(topic_path, payload)

Support

  • For custom templates and Sendgrid portal access → Contact the Aventian team.
  • For Sendgrid issues → Coordinate via Aventian.