UNPKG

3.15 kBMarkdownView Raw
1## Integration Creation
2Integrating a new platform into Kassy is a relatively simple process. It can be thought of as a special kind of module that provides I/O for Kassy.
3
4Each integration must be in its own javascript file located within the directory `core/output`. If additional files are required for an output module they must not be located within this directory or a subdirectory of it - this is to ensure that Kassy can accurately search for new integrations.
5
6### Methods
7Each integration must provide the following methods:
8
9#### `exports.start(callback)`
10Called when the integration should start up.
11
12Arguments:
13- `callback` - A function that should be called when a message is received. See below for details. Function.
14- <i>Return:</i> `undefined`
15
16###### `callback(api, event)`
17Should be called when a message is received from your chat service.
18
19Arguments:
20- `api` - Provides methods for the end modules to call. Refer to [module documentation](ModuleCreation.md) under the API section for what should be provided. Note also that not all methods need be provided if you are using shim (see below). Object.
21- `event` - Provides details about the message received. Refer to [module documentation](ModuleCreation.md) under the event section for what should be provided. Note that the fields starting with `argument` should not be provided, can be generated using shim (see below). Object.
22- <i>Returns:</i> `undefined`
23
24#### `exports.stop()`
25Called when the integration should stop.
26
27Please note: in order to ensure restarting actually correctly reloads changes, it is necessary to treat this method as if it is synchronous. For the most part this can be a best effort job, and at the very least prevent new messages being received after this method is called. It is imperative that after this method is called, your integration halts such that no background operation is keeping Kassy alive.
28
29Arguments:
30- <i>Return:</i> `undefined`
31
32### Shim
33Not all chat platforms provide every piece of functionality. As a result implementing the API for each one of the missing bits of functionality is a needless hassle. Instead `shim` should be used in your integration. It will provide fallback methods where you have not created them.
34
35Usage Example:
36```
37var myApiObject = {
38 sendMessage = function(....){}
39};
40
41var api = shim.createIntegration(myApiObject); // pass this api to callback
42```
43This will ensure that although the `myApiObject` only provides a `sendMessage()` implementation, the api generated will have all methods, with fallbacks.
44It will also ensure that any future APIs that are created will not break your integration.
45
46Shim can also be used to generate event objects for a callback.
47Example:
48```
49exports.start = function(callback) {
50....
51 var threadId = getThreadId(),
52 content = getMessageBody(),
53 senderId = getSenderId(),
54 senderName = getSenderName();
55
56 var event = shim.createEvent(threadId, senderId, senderName, content);
57 callback(api, event);
58...
59}
60```
61This will simply copy the required fields into a new object that can be used with the callback.