The Messages module enables mentors to communicate directly with players through automated messages.
The module lets you fetch, display, and manage player protection messages for a customer. Messages are localised, paginated, and support read/archive state as well as call-to-actions.
Messages are configured and sent through Automations. They are generated based on predefined triggers and workflows, allowing mentors to engage players at the right moment.
Mentor tracks how players interact with messages, including:
These engagement events are recorded and can be used to measure the effectiveness of mentor communications.
Message interactions are overlaid on player timelines, providing additional context for player behavior and outcomes.
By combining communication events with other player activities, mentors can:
| Method | Returns |
|---|---|
session.messages() |
All messages (any status) |
session.activeMessages() |
Non-archived messages |
session.unreadMessages() |
Unread messages only |
session.archivedMessages() |
Archived messages |
session.message(messageId) |
Single message by ID |
const { data, totalItems, totalPages } = await session.activeMessages({
page: 0,
limit: 10,
});
All list methods accept optional { page, limit, language, country }. Pages are zero-based and limit must be between 1 and 10 (default: 10).
All message methods are suspend functions. Call them from a coroutine.
import ai.neccton.lighthouse.MessageListOptions
val result = session.activeMessages(
MessageListOptions(page = 0, limit = 10),
)
val messages = result.data
val totalItems = result.totalItems
val totalPages = result.totalPages
Each list method accepts an optional MessageListOptions instance to override pagination or localisation for that call. Without one, it uses page = 0, limit = 10, and the session's language and country defaults. limit must be between 1 and 10.
All message methods are asynchronous and can throw. Call them from an asynchronous context.
import LighthouseSDK
let result = try await session.activeMessages(
options: MessageListOptions(page: 0, limit: 10)
)
let messages = result.data
let totalItems = result.totalItems
let totalPages = result.totalPages
Each list method accepts an optional MessageListOptions value to override pagination or localisation for that call. Without one, it uses page = 0, limit = 10, and the session's language and country defaults. limit must be between 1 and 10.
await session.markMessageRead(messageId);
await session.markAllMessagesRead();
await session.archiveMessage(messageId);
await session.restoreMessage(messageId);
session.markMessageRead(messageId)
session.markAllMessagesRead()
session.archiveMessage(messageId)
session.restoreMessage(messageId)
try await session.markMessageRead(messageId)
try await session.markAllMessagesRead()
try await session.archiveMessage(messageId)
try await session.restoreMessage(messageId)
Each mutation dispatches a typed CustomEvent on success. Use these for optimistic UI updates — no need to re-fetch the full list.
session.addEventListener('messageRead', (e) => {
// e.detail.messageId
});
session.addEventListener('messageArchived', (e) => {
// e.detail.messageId
});
session.addEventListener('messageRestored', (e) => {
// e.detail.messageId
});
session.addEventListener('allMessagesRead', (e) => {
// e.detail.updatedMessages
});
Android does not dispatch local mutation events. After a successful mutation, update your ViewModel or Compose state, or reload the affected message list.
Handle the result of the mutation directly:
scope.launch {
val activeSession = session ?: return@launch
runCatching {
activeSession.markMessageRead(messageId)
}.onSuccess {
// The message was marked as read. Update UI state if needed.
}.onFailure {
// Handle the failed API call.
}
}
iOS does not dispatch local mutation events. Handle the result of the asynchronous mutation directly:
Task {
do {
try await session.markMessageRead(messageId)
// The message was marked as read. Update UI state if needed.
} catch {
// Handle the failed API call.
}
}
Every message can contain one or more call-to-actions. Each CallToAction has an identifier (machine-readable key) and a translation (localized button label).
When the user taps a call-to-action, you must report the engagement back to Neccton. This is how player protection interventions are tracked.
Important: Only call
engageCallToActionon real user interaction — never speculatively.
for (const cta of message.callToActions) {
console.log(cta.identifier); // e.g. "OPEN_LIMIT_SETTINGS"
console.log(cta.translation); // e.g. "Set deposit limit"
}
button.addEventListener('click', async () => {
await session.engageCallToAction(message.customerMessageId, cta.identifier);
// then navigate the user to the relevant screen
});
Call the SDK from the user's click handler, in a coroutine:
viewModelScope.launch {
session.engageCallToAction(
message.customerMessageId,
callToAction.identifier,
)
// Then navigate the user to the relevant screen.
}
Button(callToAction.translation) {
Task {
do {
try await session.engageCallToAction(
message.customerMessageId,
callToActionIdentifier: callToAction.identifier
)
// Then navigate the user to the relevant screen.
} catch {
// Handle the failed API call.
}
}
}
npm install @neccton-gmbh/lighthouse-web
pnpm add @neccton-gmbh/lighthouse-web
yarn add @neccton-gmbh/lighthouse-web
Requires Angular 17+.
The service accepts a fetchRefreshToken function via initialize(). When the refresh token expires, it calls it again and re-initializes silently — no interruption for the end user.
import { Injectable, signal } from '@angular/core';
import { LighthouseSession } from '@neccton-gmbh/lighthouse-web';
import type { CustomerMessage, InitializeOptions } from '@neccton-gmbh/lighthouse-web';
@Injectable({ providedIn: 'root' })
export class LighthouseService {
readonly messages = signal<CustomerMessage[]>([]);
readonly loading = signal(false);
private session: LighthouseSession | null = null;
private fetchRefreshToken!: () => Promise<string>;
private options?: InitializeOptions;
async initialize(fetchRefreshToken: () => Promise<string>, options?: InitializeOptions) {
this.fetchRefreshToken = fetchRefreshToken;
this.options = options;
await this.init();
}
private async init() {
const token = await this.fetchRefreshToken();
this.session = await LighthouseSession.initialize(token, this.options);
this.session.addEventListener('refreshTokenExpired', () => this.init());
this.session.addEventListener('messageRead', (e) => {
this.messages.update((prev) =>
prev.map((m) =>
m.customerMessageId === e.detail.messageId ? { ...m, readDate: new Date().toISOString() } : m,
),
);
});
this.session.addEventListener('messageArchived', (e) => {
this.messages.update((prev) => prev.filter((m) => m.customerMessageId !== e.detail.messageId));
});
this.session.addEventListener('allMessagesRead', () => {
this.messages.update((prev) => prev.map((m) => ({ ...m, readDate: new Date().toISOString() })));
});
await this.loadMessages();
}
async loadMessages() {
if (!this.session) return;
this.loading.set(true);
const { data } = await this.session.activeMessages();
this.messages.set(data);
this.loading.set(false);
}
markRead(messageId: string) {
return this.session?.markMessageRead(messageId);
}
archive(messageId: string) {
return this.session?.archiveMessage(messageId);
}
restore(messageId: string) {
return this.session?.restoreMessage(messageId);
}
engageCallToAction(messageId: string, identifier: string) {
return this.session?.engageCallToAction(messageId, identifier);
}
}
import { Component, inject, OnInit } from '@angular/core';
import { LighthouseService } from './lighthouse.service';
async function fetchRefreshToken(): Promise<string> {
const res = await fetch('/api/lighthouse-token');
const { refreshToken } = await res.json();
return refreshToken;
}
@Component({
selector: 'app-messages',
standalone: true,
template: `
@if (lh.loading()) {
<p>Loading…</p>
} @else {
<ul>
@for (m of lh.messages(); track m.customerMessageId) {
<li>
<span>{{ m.message.title }}</span>
<button (click)="lh.markRead(m.customerMessageId)">Mark read</button>
<button (click)="lh.archive(m.customerMessageId)">Archive</button>
</li>
}
</ul>
}
`,
})
export class MessagesComponent implements OnInit {
readonly lh = inject(LighthouseService);
ngOnInit() {
this.lh.initialize(fetchRefreshToken, { env: 'prod' });
}
}
npm install @neccton-gmbh/lighthouse-web
pnpm add @neccton-gmbh/lighthouse-web
yarn add @neccton-gmbh/lighthouse-web
The hook accepts a fetchRefreshToken function. When the refresh token expires, the hook calls it again and re-initializes silently — no interruption for the end user.
import { useCallback, useEffect, useRef, useState } from 'react';
import { LighthouseSession } from '@neccton-gmbh/lighthouse-web';
import type { InitializeOptions } from '@neccton-gmbh/lighthouse-web';
export function useLighthouseSession(fetchRefreshToken: () => Promise<string>, options?: InitializeOptions) {
const [session, setSession] = useState<LighthouseSession | null>(null);
const optionsRef = useRef(options);
const init = useCallback(async () => {
const token = await fetchRefreshToken();
const s = await LighthouseSession.initialize(token, optionsRef.current);
s.addEventListener('refreshTokenExpired', () => {
init();
});
setSession(s);
}, [fetchRefreshToken]);
useEffect(() => {
init();
}, [init]);
return session;
}
Loads active messages on mount and applies optimistic updates via SDK events — no re-fetches needed after mutations.
import { useEffect, useState } from 'react';
import type { LighthouseSession, CustomerMessage } from '@neccton-gmbh/lighthouse-web';
export function useActiveMessages(session: LighthouseSession | null) {
const [messages, setMessages] = useState<CustomerMessage[]>([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (!session) return;
setLoading(true);
session.activeMessages().then(({ data }) => {
setMessages(data);
setLoading(false);
});
const onRead = ((e: CustomEvent<{ messageId: string }>) => {
setMessages((prev) =>
prev.map((m) =>
m.customerMessageId === e.detail.messageId ? { ...m, readDate: new Date().toISOString() } : m,
),
);
}) as EventListener;
const onArchived = ((e: CustomEvent<{ messageId: string }>) => {
setMessages((prev) => prev.filter((m) => m.customerMessageId !== e.detail.messageId));
}) as EventListener;
const onAllRead = (() => {
setMessages((prev) => prev.map((m) => ({ ...m, readDate: new Date().toISOString() })));
}) as EventListener;
session.addEventListener('messageRead', onRead);
session.addEventListener('messageArchived', onArchived);
session.addEventListener('allMessagesRead', onAllRead);
return () => {
session.removeEventListener('messageRead', onRead);
session.removeEventListener('messageArchived', onArchived);
session.removeEventListener('allMessagesRead', onAllRead);
};
}, [session]);
return { messages, loading };
}
async function fetchRefreshToken(): Promise<string> {
const res = await fetch('/api/lighthouse-token');
const { refreshToken } = await res.json();
return refreshToken;
}
function MessagesView() {
const session = useLighthouseSession(fetchRefreshToken, { env: 'prod' });
const { messages, loading } = useActiveMessages(session);
if (loading) return <p>Loading…</p>;
return (
<ul>
{messages.map((m) => (
<li key={m.customerMessageId}>
<span>{m.message.title}</span>
<button onClick={() => session?.markMessageRead(m.customerMessageId)}>Mark read</button>
<button onClick={() => session?.archiveMessage(m.customerMessageId)}>Archive</button>
</li>
))}
</ul>
);
}
npm install @neccton-gmbh/lighthouse-web
pnpm add @neccton-gmbh/lighthouse-web
yarn add @neccton-gmbh/lighthouse-web
The composable accepts a fetchRefreshToken function. When the refresh token expires, it calls it again and re-initializes silently — no interruption for the end user.
import { ref, onUnmounted } from 'vue';
import { LighthouseSession } from '@neccton-gmbh/lighthouse-web';
import type { InitializeOptions } from '@neccton-gmbh/lighthouse-web';
export function useLighthouseSession(fetchRefreshToken: () => Promise<string>, options?: InitializeOptions) {
const session = ref<LighthouseSession | null>(null);
async function init() {
const token = await fetchRefreshToken();
const s = await LighthouseSession.initialize(token, options);
s.addEventListener('refreshTokenExpired', () => init());
session.value = s;
}
init();
return { session };
}
Loads active messages on mount and applies optimistic updates via SDK events — no re-fetches needed after mutations.
import { ref, watch, onUnmounted } from 'vue';
import type { LighthouseSession, CustomerMessage } from '@neccton-gmbh/lighthouse-web';
export function useActiveMessages(session: ReturnType<typeof ref<LighthouseSession | null>>) {
const messages = ref<CustomerMessage[]>([]);
const loading = ref(false);
const onRead = ((e: CustomEvent<{ messageId: string }>) => {
const msg = messages.value.find((m) => m.customerMessageId === e.detail.messageId);
if (msg) msg.readDate = new Date().toISOString();
}) as EventListener;
const onArchived = ((e: CustomEvent<{ messageId: string }>) => {
messages.value = messages.value.filter((m) => m.customerMessageId !== e.detail.messageId);
}) as EventListener;
const onAllRead = (() => {
messages.value = messages.value.map((m) => ({
...m,
readDate: new Date().toISOString(),
}));
}) as EventListener;
watch(session, async (s, _, onCleanup) => {
if (!s) return;
loading.value = true;
const { data } = await s.activeMessages();
messages.value = data;
loading.value = false;
s.addEventListener('messageRead', onRead);
s.addEventListener('messageArchived', onArchived);
s.addEventListener('allMessagesRead', onAllRead);
onCleanup(() => {
s.removeEventListener('messageRead', onRead);
s.removeEventListener('messageArchived', onArchived);
s.removeEventListener('allMessagesRead', onAllRead);
});
});
return { messages, loading };
}
<script setup lang="ts">
import { useLighthouseSession } from './composables/useLighthouseSession';
import { useActiveMessages } from './composables/useActiveMessages';
async function fetchRefreshToken(): Promise<string> {
const res = await fetch('/api/lighthouse-token');
const { refreshToken } = await res.json();
return refreshToken;
}
const { session } = useLighthouseSession(fetchRefreshToken, { env: 'prod' });
const { messages, loading } = useActiveMessages(session);
</script>
<template>
<p v-if="loading">Loading…</p>
<ul v-else>
<li v-for="m in messages" :key="m.customerMessageId">
<span>{{ m.message.title }}</span>
<button @click="session?.markMessageRead(m.customerMessageId)">Mark read</button>
<button @click="session?.archiveMessage(m.customerMessageId)">Archive</button>
</li>
</ul>
</template>
Initialize LighthouseSession as described in the Lighthouse overview, then provide the active session to a ViewModel. The ViewModel can expose messages and loading state to either a Compose UI or a View-based UI.
import ai.neccton.lighthouse.ApiError
import ai.neccton.lighthouse.CustomerMessage
import ai.neccton.lighthouse.LighthouseSession
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
class LighthouseMessagesViewModel(
private val session: LighthouseSession,
) : ViewModel() {
private val _messages = MutableStateFlow<List<CustomerMessage>>(emptyList())
val messages: StateFlow<List<CustomerMessage>> = _messages.asStateFlow()
private val _loading = MutableStateFlow(false)
val loading: StateFlow<Boolean> = _loading.asStateFlow()
private val _error = MutableStateFlow<String?>(null)
val error: StateFlow<String?> = _error.asStateFlow()
private suspend fun refreshActiveMessages() {
_messages.value = session.activeMessages().data
}
fun loadActiveMessages() {
viewModelScope.launch {
_loading.value = true
try {
refreshActiveMessages()
} catch (error: ApiError) {
_error.value = error.message
} finally {
_loading.value = false
}
}
}
fun markMessageRead(messageId: String) {
viewModelScope.launch {
try {
session.markMessageRead(messageId)
refreshActiveMessages()
} catch (error: ApiError) {
_error.value = error.message
}
}
}
fun archiveMessage(messageId: String) {
viewModelScope.launch {
try {
session.archiveMessage(messageId)
refreshActiveMessages()
} catch (error: ApiError) {
_error.value = error.message
}
}
}
fun engageCallToAction(messageId: String, identifier: String) {
viewModelScope.launch {
try {
session.engageCallToAction(messageId, identifier)
} catch (error: ApiError) {
_error.value = error.message
}
}
}
}
Call loadActiveMessages() when the messages screen opens. Call the ViewModel's mutation methods from the UI, for example:
viewModel.markMessageRead(message.customerMessageId)
viewModel.archiveMessage(message.customerMessageId)
viewModel.engageCallToAction(
message.customerMessageId,
callToAction.identifier,
)
Initialize LighthouseSession as described in the Lighthouse overview, then provide the active session to an ObservableObject used by your SwiftUI view.
import Combine
import Foundation
import LighthouseSDK
@MainActor
final class LighthouseMessagesViewModel: ObservableObject {
@Published private(set) var messages: [CustomerMessage] = []
@Published private(set) var isLoading = false
@Published private(set) var errorMessage: String?
private let session: LighthouseSession
init(session: LighthouseSession) {
self.session = session
}
private func refreshActiveMessages() async throws {
messages = try await session.activeMessages().data
}
func loadActiveMessages() async {
isLoading = true
defer { isLoading = false }
do {
try await refreshActiveMessages()
} catch {
errorMessage = error.localizedDescription
}
}
func markMessageRead(_ messageId: String) {
Task {
do {
try await session.markMessageRead(messageId)
try await refreshActiveMessages()
} catch {
errorMessage = error.localizedDescription
}
}
}
func archiveMessage(_ messageId: String) {
Task {
do {
try await session.archiveMessage(messageId)
try await refreshActiveMessages()
} catch {
errorMessage = error.localizedDescription
}
}
}
func engageCallToAction(messageId: String, identifier: String) {
Task {
do {
try await session.engageCallToAction(
messageId,
callToActionIdentifier: identifier
)
} catch {
errorMessage = error.localizedDescription
}
}
}
}
import SwiftUI
struct MessagesView: View {
@StateObject private var viewModel: LighthouseMessagesViewModel
init(session: LighthouseSession) {
_viewModel = StateObject(
wrappedValue: LighthouseMessagesViewModel(session: session)
)
}
var body: some View {
List(viewModel.messages, id: \.customerMessageId) { message in
VStack(alignment: .leading) {
Text(message.message.title)
Button("Mark read") {
viewModel.markMessageRead(message.customerMessageId)
}
Button("Archive") {
viewModel.archiveMessage(message.customerMessageId)
}
ForEach(message.callToActions, id: \.identifier) { callToAction in
Button(callToAction.translation) {
viewModel.engageCallToAction(
messageId: message.customerMessageId,
identifier: callToAction.identifier
)
}
}
}
}
.task {
await viewModel.loadActiveMessages()
}
}
}