Skip to content

Commit

Permalink
Multi Instance widget core (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunu authored Mar 11, 2020
1 parent 8548539 commit 86c8405
Show file tree
Hide file tree
Showing 15 changed files with 1,494 additions and 4,615 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
]
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties"
]
}
85 changes: 47 additions & 38 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## init

- Initialises the widget
- Resolves promise on connection success with botName and history
- Rejects promise if hookURL is of invalid format
## constructor

### Parameters

- `configuration` **[object][1]**
- `configuration.apiKey` **[string][2]**
- `configuration.hookURL` **[string][2]**
- `configuration.conversationLogging` **[boolean][3]**
- `onMessage` **[function][4]** callback for incoming messages

Returns **[Promise][5]&lt;[object][1]>** where object = {botName: string, history: Array[{content: string, made_by: string}]}
## getBotName

Returns a Promise that resolves with bot name

### Parameters

- `hookURL` **[string][2]** (optional, default `this.configuration.hookURL`)
- `apiKey` **[string][2]** (optional, default `this.configuration.apiKey`)

Returns **[Promise][4]&lt;([Response][5] | never)>**

## init

- Initialises the widget
- Resolves promise on connection success with botName and history
- Rejects promise if it fails

Returns **[Promise][4]&lt;[object][1]>** where object = {botName: string, history: Array[{content: string, made_by: string}]}

## onMessage

Set callback for incoming messages

### Parameters

- `callback` **[function][6]** callback for incoming messages

## send

Expand All @@ -30,27 +50,27 @@ Sends a message if connected, else queues it
without having the user to send a message first
- Must be called after init

## onConnectionChange
## endSession

Sets callback for connection change
- Closes socket connection for good
- Clears callback references

### Parameters
## clearSession

- `callback` **[function][4]** (isConnected: bool)
- Ends session
- Clears all data & cookie

## attachToPayload
## onConnectionChange

- Adds a property to the payload object
- If the property already exists, its value will be overwritten
Sets callback for connection change

### Parameters

- `key` **[string][2]**
- `value` **any**
- `callback` **[function][6]** (isConnected: bool)

## setMetadata
## attachToPayload

- Adds a property to the metadata object in payload
- Adds a property to the payload object
- If the property already exists, its value will be overwritten

### Parameters
Expand Down Expand Up @@ -84,32 +104,21 @@ Returns **[boolean][3]**

Returns a promise that resolves if and when user_id_cookie is available

Returns **[Promise][5]&lt;[string][2]>**
Returns **[Promise][4]&lt;[string][2]>**

## getBotName
## setMetadata

Returns a Promise that resolves with bot name
- Adds a property to the metadata object in payload
- If the property already exists, its value will be overwritten

### Parameters

- `hookURL` **[string][2]** (optional, default `store.configuration.hookURL`)
- `apiKey` **[string][2]** (optional, default `store.configuration.apiKey`)

Returns **[Promise][5]&lt;([Response][6] | never)>**

## endSession

- Closes socket connection for good
- Clears callback references

## clearSession

- Ends session
- Clears all data & cookie
- `key` **[string][2]**
- `value` **any**

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[6]: https://developer.mozilla.org/docs/Web/Guide/HTML/HTML5
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[5]: https://developer.mozilla.org/docs/Web/Guide/HTML/HTML5
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = {
},
},
},
setupFiles: ['jest-localstorage-mock'],
setupFiles: [],
};
Loading

0 comments on commit 86c8405

Please sign in to comment.