Documentation

Intercom

Communication inter-bots par messages et topics.

onFreeMessage

Enregistre un gestionnaire appelé à chaque message libre (broadcast) reçu via l'intercom.

api.intercom.onFreeMessage: (handler: LiteEventHandler<FreeMessage>) => void

Exemple

api.intercom.onFreeMessage((message) => {
  if (message.type === 'OutOfStockMessage') {
    api.intercom.unsubscribeTopic('market');
  }
});

onPrivateMessage

Enregistre un gestionnaire appelé à chaque message privé inter-bots reçu via l'intercom.

api.intercom.onPrivateMessage: (handler: LiteEventHandler<PrivateMessage>) => void

Exemple

api.intercom.onPrivateMessage((message) => {
  if (message.type === 'HelloMessage') {
    api.intercom.sendPrivateMessage({ type: 'HelloMessage', to: message.from });
  }
});

onStringMessage

Enregistre un gestionnaire appelé à chaque message texte brut reçu via l'intercom.

api.intercom.onStringMessage: (handler: LiteEventHandler<string>) => void

Exemple

api.intercom.onStringMessage((text) => {
  if (text === 'stop') {
    api.intercom.unsubscribeAll();
  }
});

publishMessage

Publie un contenu texte sur un topic de l'intercom.

api.intercom.publishMessage: (topic: string, content: string) => void

Exemple

api.intercom.publishMessage('market', 'buying runes');

sendFreeMessage

Envoie un message libre structuré sur un topic, éventuellement ciblé sur un serveur.

api.intercom.sendFreeMessage: ( topic: string, m: Omit<FreeMessage, 'serverId'>, serverId?: number ) => void

Exemple

api.intercom.sendFreeMessage('kamas', {
  type: 'TellMeYourKamasAmountMessage',
  username: 'Bob',
});

sendPrivateMessage

Envoie un message privé structuré à un autre bot via l'intercom.

api.intercom.sendPrivateMessage: <T extends PrivateMessage>(pm: Omit<T, 'from'>) => void

Exemple

api.intercom.sendPrivateMessage({
  type: 'PositionMessage',
  to: 'Bob',
  mapId: 153093123,
});

subscribeTopic

Abonne le personnage à un topic de l'intercom.

api.intercom.subscribeTopic: (topic: string) => void

Exemple

api.intercom.subscribeTopic('market');

unsubscribeAll

Désabonne le personnage de tous les topics de l'intercom.

api.intercom.unsubscribeAll: () => void

Exemple

api.intercom.unsubscribeAll();

unsubscribeTopic

Désabonne le personnage d'un topic donné (ou du topic courant si omis).

api.intercom.unsubscribeTopic: (topic?: string) => void

Exemple

api.intercom.unsubscribeTopic('market');