IConnector interface

Implemented by connector plugins for the UniversalBot.

Methods

delete(IAddress, (err: Error) => void)

(Optional) method that can be called to delete a message that was previously sent using send().

onEvent((events: IEvent[], callback?: (err: Error) => void) => void)

Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel.

onInvoke((event: IEvent, callback?: (err: Error, body: any, status?: number) => void) => void)

(Optional) Called by the UniversalBot at registration time to register a handler for receiving incoming invoke events. Invoke events are special events which are expected to return a body inline as part of the response to the received request.

send(IMessage[], (err: Error, addresses?: IAddress[]) => void)

Sends outgoing message(s) to a user. This method will ultimately get called anytime you call UniversalBot.send() or Session.send(). You can manually call this method using session.connector.send() as a convenient way of getting the address of the message that was sent. You can then store this address and use it at a later point in time to either update or delete the message. The one thing to keep in mind is that if you manually call session.connector.send() you will bypass any middleware that the outgoing message would normally run through. Calling session.send(msg).sendBatch(function (err, addresses) { }) does the same thing but ensures that the outgoing message is sent through middleware.

startConversation(IAddress, (err: Error, address?: IAddress) => void)

Called when a UniversalBot wants to start a new proactive conversation with a user. The connector should return an address with a properly formated IAddress.conversation field. This will typically be called when you call UniversalBot.beginDialog() but will also be called anytime IAddress.conversation is null for a message being sent.

update(IMessage, (err: Error, address?: IAddress) => void)

(Optional) method that can be called to replace a message that was previously sent using send().

Method Details

delete(IAddress, (err: Error) => void)

(Optional) method that can be called to delete a message that was previously sent using send().

function delete(address: IAddress, callback: (err: Error) => void)

Parameters

address
IAddress

The address of the message to delete.

callback

(err: Error) => void

Function to invoke once the operation is completed.

onEvent((events: IEvent[], callback?: (err: Error) => void) => void)

Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel.

function onEvent(handler: (events: IEvent[], callback?: (err: Error) => void) => void)

Parameters

handler

(events: IEvent[], callback?: (err: Error) => void) => void

The function that should be called anytime an event is received that is not of type "invoke".

onInvoke((event: IEvent, callback?: (err: Error, body: any, status?: number) => void) => void)

(Optional) Called by the UniversalBot at registration time to register a handler for receiving incoming invoke events. Invoke events are special events which are expected to return a body inline as part of the response to the received request.

function onInvoke(handler: (event: IEvent, callback?: (err: Error, body: any, status?: number) => void) => void)

Parameters

handler

(event: IEvent, callback?: (err: Error, body: any, status?: number) => void) => void

The function that should be called anytime an "invoke" event is received.

send(IMessage[], (err: Error, addresses?: IAddress[]) => void)

Sends outgoing message(s) to a user. This method will ultimately get called anytime you call UniversalBot.send() or Session.send(). You can manually call this method using session.connector.send() as a convenient way of getting the address of the message that was sent. You can then store this address and use it at a later point in time to either update or delete the message. The one thing to keep in mind is that if you manually call session.connector.send() you will bypass any middleware that the outgoing message would normally run through. Calling session.send(msg).sendBatch(function (err, addresses) { }) does the same thing but ensures that the outgoing message is sent through middleware.

function send(messages: IMessage[], callback: (err: Error, addresses?: IAddress[]) => void)

Parameters

messages

IMessage[]

Array of message(s) to send the user.

callback

(err: Error, addresses?: IAddress[]) => void

Function to invoke once the operation is completed.

startConversation(IAddress, (err: Error, address?: IAddress) => void)

Called when a UniversalBot wants to start a new proactive conversation with a user. The connector should return an address with a properly formated IAddress.conversation field. This will typically be called when you call UniversalBot.beginDialog() but will also be called anytime IAddress.conversation is null for a message being sent.

function startConversation(address: IAddress, callback: (err: Error, address?: IAddress) => void)

Parameters

address
IAddress

The address of the user to start the conversation for. The IAddress.conversation field should be null.

callback

(err: Error, address?: IAddress) => void

Function to invoke once the operation is completed.

update(IMessage, (err: Error, address?: IAddress) => void)

(Optional) method that can be called to replace a message that was previously sent using send().

function update(message: IMessage, callback: (err: Error, address?: IAddress) => void)

Parameters

message
IMessage

The message to overwrite an existing message with. The message.address field should contain an address returned from a previous call to send().

callback

(err: Error, address?: IAddress) => void

Function to invoke once the operation is completed.