Skip to content

Latest commit

 

History

History
245 lines (194 loc) · 7.39 KB

Api.md

File metadata and controls

245 lines (194 loc) · 7.39 KB

Functions

sendMessage(message, thread)

Send a message to a chat.

sendUrl(url, thread)

Embeds a URL within a chat.

sendImage(type, image, description, thread)

Send an image to a chat.

sendFile(type, file, description, thread)

Send a file to a chat.

sendTyping(thread)

Starts the self-cancelling typing indicator.

setTitle(title, thread)

Sets the title of a chat thread.

sendPrivateMessage(message, thread)

Sends a private message to a person.

sendMessageToMultiple(message, threads)

Sends a message to mutiple loaded integrations.

getUsers(thread)Object

Gets the users within a thread.

random(arr)Object

Convenience method for selecting random items from an array.

http()Object

Convenience method for performing http requests.

Properties

commandPrefix

The prefix that should be used before commands on the current integration.


sendMessage(message, thread)

Send a message to a chat.

Kind: API method

Param Type Description
message string the message to send.
thread string the ID of the thread to send the message to.

Example
To send 'Hello World' to the current thread:

api.sendMessage('Hello World', event.thread_id);

sendUrl(url, thread)

Embeds a URL within a chat.

Kind: API method

Param Type Description
url string the url to embed.
thread string the ID of the thread to embed the url in.

Example
To send 'http://google.com' to the current thread:

api.sendUrl('http://google.com', event.thread_id);

sendImage(type, image, description, thread)

Send an image to a chat.

Kind: API method

Param Type Description
type string type of image that is being sent. By default this can be 'url' or 'file' although individual integrations can expand support to other types.
image string | Object image object for the type provided.
description string description of the image being sent.
thread string the ID of the thread to send the image to.

Example
To send the image 'http://i.imgur.com/unrseYB.png' to the current thread with the description 'Hello World':

api.sendImage('url', 'http://i.imgur.com/unrseYB.png', 'Hello World', event.thread_id);

sendFile(type, file, description, thread)

Send a file to a chat.

Kind: API method

Param Type Description
type string type of file that is being sent. By default this can be 'url' or 'file' although individual integrations can expand support to other types.
file string | Object file object for the type provided.
description string description of the file being sent.
thread string the ID of the thread to send the file to.

sendTyping(thread)

Starts the self-cancelling typing indicator.

Note:
Typing indicators are self-cancelling; that is, when this method is called the integration should work out for itself when to stop the typing indicator. It is automatically called when a module is invoked.

Kind: API method

Param Type Description
thread string the thread ID of the thread to send the typing indicator to.

Example
To start the typing indicator in the current thread:

api.sendTyping(event.thread_id);

setTitle(title, thread)

Sets the title of a chat thread.

Kind: API method

Param Type Description
title string the new title of the thread.
thread string the thread ID of the thread to set the title of.

Example
To set the title of the current thread to 'Hello World':

api.setTitle('Hello World', event.thread_id);

sendPrivateMessage(message, thread)

Sends a private message to a person.

Kind: API method
See: sendMessage

Param Type Description
message string message to send.
thread string the ID of the person to send the message to.

sendMessageToMultiple(message, threads)

Sends a message to multiple loaded integrations.

Kind: API method
Note: Integration authors should NOT implement this method.

Param Type Description
message string message to send.
threads Object object representing the threads to send the message to.

Example
For example, to send the message "Hello World!" to the Facebook threads 1234 and 5678 as well as the Slack threads 'abcd' and 'efgh':

api.sendMessageToMultiple("Hello World!", {
    "facebook": [1234, 5678],
    "slack": ['abcd', 'efgh']
});

getUsers(thread) ⇒ Object

Gets the users within a thread.

Kind: API method
Returns: Object - an object similar to the example below.

Param Type Description
thread string thread to get the users of.

Example

{
    '<someUserId>': {
        name: '<someUserName>'
    }
}

random(arr) ⇒ Object

Convenience method for selecting random items from an array.

Kind: API method
Note: Integration authors should NOT implement this method.
Returns: Object - random item of the array.

Param Type Description
arr Array array to select a random item from.

Example

let array = ['foo', 'bar', 'baz'];
let randomItem = api.random(array); // foo, bar or baz

http() ⇒ Object

Convenience method for performing http requests.

Kind: API method
Note: Integration authors should NOT implement this method.
Returns: Object - an http.clientRequest.
See: https://github.com/technoweenie/node-scoped-http-client, client.create for API details.

commandPrefix ⇒ string

The prefix that should be used before commands on the current integration.
Using the prefix is optional but highly recommended within your commands.

Kind: Object property
Example
If the command prefix was /, and you had a command foo, then to activate your command the following should be required:

/foo