Canaux
Gestion des canaux de messagerie via @ziwako/message — CRUD, participants, device tokens, statistiques, envoi.
La ressource Channels gère les canaux de messagerie : conteneurs de conversation liés à
un type (push, email, sms, chat, ...), avec participants, tokens d'appareil,
statistiques et envoi de messages dans le canal.
- Factory :
getChannels()(@ziwako/message/axios) - Types :
Channel,ChannelResponse,ChannelListResponse,MessageListResponse,CreateChannelBody,UpdateChannelBody,AddParticipantsBody,JoinChannelBody,LeaveChannelBody,SetDeviceTokenBody,RemoveDeviceTokenBody,MarkAsReadBody,SendMessageBody,ListChannelParams,ListMessagesParams - Endpoints :
POST /channels,GET /channels,GET /channels/{id},PUT /channels/{id},DELETE /channels/{id},/channels/{id}/participants,/channels/{id}/join,/channels/{id}/leave,/channels/{id}/stats,/channels/{id}/setDeviceToken,/channels/{id}/removeDeviceToken,/channels/{id}/messages/mark_as_read,/channels/{id}/send-message,/channels/{id}/messages,GET /channels/scope/{scope}
import { configure, getChannels } from '@ziwako/message/axios';
configure({ accessToken: '...' });
const channels = getChannels();CRUD
createChannel
Crée un canal. Le champ type est requis (ex. push, email, sms, chat) ; une
intégration peut être fournie (EmailIntegration, PushFirebaseIntegration,
SmsIntegration).
Signature : createChannel(createChannelBody?: CreateChannelBody) → Promise<ChannelResponse>
const response = await channels.createChannel({
title: 'Push utilisateur 123',
type: 'push',
owner: profilId,
integration: {
firebase: {
projectId: 'ziwako-push',
clientEmail: 'firebase-adminsdk@ziwako-push.iam.gserviceaccount.com',
privateKey: process.env.FIREBASE_PRIVATE_KEY,
},
},
});
console.log(response.data?.id);import { useCreateChannel } from '@ziwako/message/react-query';
const mutation = useCreateChannel();
mutation.mutate({ data: { title: 'Canal promo', type: 'email', owner: profilId } });listChannel
Liste paginée des canaux.
Signature : listChannel(params?: ListChannelParams) → Promise<ChannelListResponse>
const list = await channels.listChannel({ page: 1, limit: 20, filter: { owner: profilId } });
console.log(list.data?.docs);import { useListChannel } from '@ziwako/message/react-query';
const { data } = useListChannel({ page: 1, limit: 20 });getChannel
Récupère un canal par son id.
Signature : getChannel(id: string) → Promise<ChannelResponse>
const response = await channels.getChannel('64b8f2...');
console.log(response.data?.title, response.data?.type);import { useGetChannel } from '@ziwako/message/react-query';
const { data } = useGetChannel(channelId, { query: { enabled: !!channelId } });updateChannel
Met à jour un canal (titre, intégration, participants...).
Signature : updateChannel(id: string, updateChannelBody?: UpdateChannelBody) → Promise<ChannelResponse>
await channels.updateChannel(channelId, { title: 'Canal promo 2026' });import { useUpdateChannel } from '@ziwako/message/react-query';
const mutation = useUpdateChannel();
mutation.mutate({ id: channelId, data: { title: 'Canal promo 2026' } });deleteChannel
Supprime un canal.
Signature : deleteChannel(id: string) → Promise<DeleteChannel200>
await channels.deleteChannel(channelId);import { useDeleteChannel } from '@ziwako/message/react-query';
const mutation = useDeleteChannel();
mutation.mutate({ id: channelId });getScopedChannel
Récupère le canal associé à un scope (ex. orders:new, appointment:reminder).
Signature : getScopedChannel(scope: string) → Promise<ChannelResponse>
const channel = await channels.getScopedChannel('orders:new');
console.log(channel.data?.id);import { useGetScopedChannel } from '@ziwako/message/react-query';
const { data } = useGetScopedChannel('orders:new', { query: { enabled: !!scope } });Participants
addParticipants
Ajoute des participants à un canal.
Signature : addParticipants(id: string, addParticipantsBody?: AddParticipantsBody) → Promise<AddParticipants200>
await channels.addParticipants(channelId, {
participants: [{ profilId: '64b8f2...', role: 'member' }],
});import { useAddParticipants } from '@ziwako/message/react-query';
const mutation = useAddParticipants();
mutation.mutate({ id: channelId, data: { participants: [{ profilId: '64b8f2...', role: 'member' }] } });getParticipant
Récupère les participants d'un canal.
Signature : getParticipant(id: string) → Promise<GetParticipant200>
const participants = await channels.getParticipant(channelId);
console.log(participants.data);import { useGetParticipant } from '@ziwako/message/react-query';
const { data } = useGetParticipant(channelId);removeParticipant
Retire un participant du canal.
Signature : removeParticipant(id: string, profilId: string) → Promise<RemoveParticipant200>
await channels.removeParticipant(channelId, '64b8f2...');import { useRemoveParticipant } from '@ziwako/message/react-query';
const mutation = useRemoveParticipant();
mutation.mutate({ id: channelId, profilId: '64b8f2...' });joinChannel
Rejoint un canal (avec des options d'adhésion).
Signature : joinChannel(id: string, joinChannelBody?: JoinChannelBody) → Promise<JoinChannel200>
await channels.joinChannel(channelId, { profilId: '64b8f2...' });import { useJoinChannel } from '@ziwako/message/react-query';
const mutation = useJoinChannel();
mutation.mutate({ id: channelId, data: { profilId: '64b8f2...' } });leaveChannel
Quitte un canal.
Signature : leaveChannel(id: string, leaveChannelBody?: LeaveChannelBody) → Promise<LeaveChannel200>
await channels.leaveChannel(channelId, { profilId: '64b8f2...' });import { useLeaveChannel } from '@ziwako/message/react-query';
const mutation = useLeaveChannel();
mutation.mutate({ id: channelId, data: { profilId: '64b8f2...' } });Statistiques & tokens
getStatistique
Statistiques d'un canal (messages envoyés, taux de lecture...).
Signature : getStatistique(id: string) → Promise<GetStatistique200>
const stats = await channels.getStatistique(channelId);
console.log(stats.data?.sent, stats.data?.delivered);import { useGetStatistique } from '@ziwako/message/react-query';
const { data } = useGetStatistique(channelId);setDeviceToken
Associe un token d'appareil (ex. ExpoPushToken / FCM) au canal, pour les notifications push.
Signature : setDeviceToken(id: string, setDeviceTokenBody?: SetDeviceTokenBody) → Promise<SetDeviceToken200>
await channels.setDeviceToken(pushChannelId, {
registrationToken: 'ExponentPushToken[xxxxxxxx]',
});import { useSetDeviceToken } from '@ziwako/message/react-query';
const mutation = useSetDeviceToken();
mutation.mutate({ id: pushChannelId, data: { registrationToken: 'ExponentPushToken[xxxxxxxx]' } });removeDeviceToken
Retire un token d'appareil d'un canal.
Signature : removeDeviceToken(id: string, removeDeviceTokenBody?: RemoveDeviceTokenBody) → Promise<RemoveDeviceToken200>
await channels.removeDeviceToken(channelId, {
registrationToken: 'ExponentPushToken[xxxxxxxx]',
});import { useRemoveDeviceToken } from '@ziwako/message/react-query';
const mutation = useRemoveDeviceToken();
mutation.mutate({ id: channelId, data: { registrationToken: 'ExponentPushToken[xxxxxxxx]' } });Messages du canal
markAsRead
Marque les messages d'un canal comme lus.
Signature : markAsRead(id: string, markAsReadBody?: MarkAsReadBody) → Promise<MarkAsRead200>
await channels.markAsRead(channelId, { messageIds: ['64b8f2...'] });import { useMarkAsRead } from '@ziwako/message/react-query';
const mutation = useMarkAsRead();
mutation.mutate({ id: channelId, data: { messageIds: ['64b8f2...'] } });sendMessage
Envoie un message dans un canal spécifique.
Signature : sendMessage(id: string, sendMessageBody?: SendMessageBody) → Promise<SendMessage200>
const response = await channels.sendMessage(channelId, {
title: 'Confirmation de commande',
body: 'Bonjour {{name}}, votre commande est confirmée.',
type: 'email',
owner: profilId,
scope: 'orders:confirmed',
variables: { name: 'Client' },
emailConfig: {
subject: 'Commande confirmée',
from: 'no-reply@ziwako.com',
to: ['client@example.com'],
},
});
console.log(response.data?.id);import { useSendMessage } from '@ziwako/message/react-query';
const mutation = useSendMessage({
mutation: {
onSuccess: () => toast.success('Message envoyé'),
},
});
mutation.mutate({
id: channelId,
data: {
title: 'Confirmation',
body: 'Bonjour {{name}}, votre commande est confirmée.',
type: 'email',
owner: profilId,
variables: { name: 'Client' },
},
});listMessages
Liste les messages d'un canal (paginé).
Signature : listMessages(id: string, params?: ListMessagesParams) → Promise<MessageListResponse>
const list = await channels.listMessages(channelId, { page: 1, limit: 20 });
console.log(list.data?.docs);import { useListMessages } from '@ziwako/message/react-query';
const { data } = useListMessages(channelId, { page: 1, limit: 20 });