Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to reflect moving to streams in RC-side of development #15

Merged
merged 16 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,26 @@ but have not been joined yet this method will join to those rooms automatically.

If `allPublic` is true, the `rooms` option will be ignored.

### `driver.addClientToStack(clientDetails)`

Adds details about the client using the SDK to the stack of clients.

It must be called before the `driver.login()` function, since the data is sent right after login.

clientDetails has a `name` and a `version` field, both strings.

```
driver.addClientToStack({
name: 'ExampleBotFramework Rocket.Chat Adapter',
version: '0.4.2'
})
```

### `driver.setCustomClientData(clientData)`

Set additional data about the client using the SDK to be sent to the server.

It must be called before the `driver.login()` function, otherwise it will have no effect.
It must be called before the `driver.login()` function, since the data is sent right after login.

Useful only when adding new features in Rocket.Chat that depend on the client.

Expand All @@ -282,14 +297,19 @@ do not have this feature, so the bot manager interface in Rocket.Chat will have
to differentiate between them, hence the need to define its data.

```
driver.addClientToStack({
name: 'ExampleBotFramework Rocket.Chat Adapter',
version: '0.4.2'
})

driver.setCustomClientData({
framework: 'ExampleBotFramework',
canResetConnection: true
});
})
```

Then, Rocket.Chat's interface will check if the bot is able to reset its connection and
show an UI to allow the admin to do that.
Then, Rocket.Chat's interface can check if the bot is able to reset its connection before enabling
an UI with that feature.

### `driver.registerCommandHandler(key, callback)`

Expand All @@ -310,7 +330,7 @@ The `callback` receives a `ClientCommand` object as the first parameter and retu

`ClientCommandResponse` object structure:
- ClientCommandResponse.success: Boolean indicating the success status of the command
- ClientCommandResponse.msg: Message response to the command
- Along with any other relevant property to the response

### `driver.asyncCall(method, params)`

Expand Down Expand Up @@ -601,6 +621,7 @@ rocketchat.driver.connect({ host: 'localhost:3000' }, function (err, asteroid) {
| `ROOM_CACHE_MAX_AGE` | Max age of cache for room lookups |
| `DM_ROOM_CACHE_SIZE` | Size of cache for Direct Message room lookups |
| `DM_ROOM_CACHE_MAX_AGE`| Max age of cache for DM lookups |
| `WAIT_CLIENT_COMMANDS` | Wait subscription of ClientCommands before login finishes.
| **Test configs** | |
| `ADMIN_USERNAME` | Admin user password for API |
| `ADMIN_PASS` | Admin user password for API |
Expand Down
18 changes: 16 additions & 2 deletions src/config/commandInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export interface IClientCommand {
* Structure of the object to reply to a clientCommand
*/
export interface IClientCommandResponse {
status?: number,
msg: string
success: boolean,
error?: Error,
[key: string]: any
}

/*
Expand All @@ -34,3 +35,16 @@ export interface IClientCommandHandler {
export interface IClientCommandHandlerMap {
[key: string]: IClientCommandHandler
}

/*
* Structure of the object of client data
*/
export interface ICustomClientData {
stack: Array<IClientDetails>,
[key: string]: any
}

export interface IClientDetails {
name: string,
version: string
}
4 changes: 4 additions & 0 deletions src/config/driverInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export interface ILogger {
export interface ICallback {
(error: Error | null, ...args: any[]): void
}

export interface ISessionStatistics {
[key: string]: any
}
17 changes: 16 additions & 1 deletion src/lib/driver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sinon from 'sinon'
import { expect } from 'chai'
import { silence } from './log'
import { botUser, mockUser, apiUser } from '../utils/config'
import { logout } from './api'
import { get, login, logout } from './api'
import * as utils from '../utils/testing'
import * as driver from './driver'
import * as methodCache from './methodCache'
Expand Down Expand Up @@ -116,6 +116,10 @@ describe('driver', () => {
})
})
describe('.clientCommands', () => {
/**
* Note: For them to work you have to wait for client-commands subscription
* to be fully initialized, so set ROCKETCHAT_WAIT_CLIENT_COMMANDS to true
*/
it('sets customClientData from the SDK with no customizations', async () => {
await driver.connect()
await driver.login()
Expand All @@ -132,6 +136,17 @@ describe('driver', () => {
expect(result.user.customClientData).to.deep.include(driver.customClientData)
expect(result.user.customClientData.framework).to.equal('Testing')
})
it('custom handler is called once', async () => {
driver.setCustomClientData({ framework: 'Testing' })
const callback = sinon.spy()
driver.registerCommandHandler('getStatistics', callback)
await driver.connect()
await driver.login()
// Login as admin and request stats from the bot
await login({ username: apiUser.username, password: apiUser.password })
await get('bots.getLiveStats', { username: botUser.username })
sinon.assert.calledOnce(callback)
})
})
describe('.subscribeToMessages', () => {
it('resolves with subscription object', async () => {
Expand Down
Loading