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

New livechat event handlers #248

Merged
merged 25 commits into from
Apr 23, 2020
Merged

Conversation

shiqimei
Copy link
Contributor

@shiqimei shiqimei commented Mar 26, 2020

What? β›΅

  • Add assignAgent and unassignAgent event handlers
  • Add LivechatRoomStartedHandler event handler

Why? πŸ€”

Implement partial requirements described in the issue #234

Links 🌎

https://app.asana.com/0/633285093795758/1165026712648489/f

RocketChat/Rocket.Chat#17033

PS πŸ‘€

d-gubert and others added 5 commits February 24, 2020 20:51
* Apps.engine.ui (#131)

* Add interfaces IExternalComponent and IExternalComponentExtend

* Add externalComponents property for IConfigurationExtend

* export IExternalComponent

* Add interface IExternalComponentLocationOptions

* implement the interface IExternalComponentsExtend

* export ExternalComponentsExtend

* Add externalComponentManager for AppManager

* implement AppExternalComponentManager

* Implement IExternalComponentBridge

* Add getExternalComponentBridge method for AppBridges

* export AppExternalComponentManager

* Update getConfigurationExtend method for AppAccessorManager

* [TEST] Update appBridge and add externalComponentBridge

* Update related test scripts

* Remove IExternalComponentBridge interface

* AppExternalComponentManager maintains the list of all registered components itself

* Update test scripts

* Add webhooks interface for the external component

* Update the interface IExternalComponent

* Add description field to the interface IExternalComponent

* Apps.engine.ui.sdk (#132)

* update IWebHooks interface

* Add util randomString

* add AppEmbeddedSDK

* move constants to src/client/constants directory

* separate initListener from call method
* rename initListener to init

* Bump alpha version

* Change version checking function to allow pre-release tags

* Add go-publish-alpha npm script

* Bump alpha version

* Add options for http requests

* Add Livechat functionality

* Add further integration with Livechat

* Refactor minor inconsistency

* Formatting improvement

* Add createToken method to LivechatCreator

* Add file property to message interface

* Add types to compiler option to allow usage of Buffer type

* Add livechat reader getter to read interface

* Add Upload reader

* Update visitor interface

* 1.6.0-beta.0

* Validate the LIVE_CHAT rooms correctly

* Update version for CI

* Access livechat room’s deparment data (#142)

* Revert "Change version checking function to allow pre-release tags"

This reverts commit 0b88a18.

* 1.7.0-alpha

* Add missing unregister component method (#144)

* chore: change comment style to obtain VS Code Intellisense

* feat: add unregisterComponent method

We made follwing changes for the AppExternalComponentManager:
* add new private property - appTouchedComponents
* add new public method unregisterComponent
* add new public method getExternalComponent

* Add unregisterComponent in the lifecycle methods

We need to call unregisterComponent method to remove the corresponding external  components from the providedComponents when following AppManager's methods are called:
*  `unload` is called
* `disable` is called <-> Disable an app
*  `remove` is called <-> Uninstall an app
*  `updateAppsMarketplaceInfo` is called and validateLicense not pass
* `initializeApp` is called and validateLicense not pass
* `enableApp` is called but is not success

* Add new AppExternalComponentManager method purgeComponent

when remove an app from the system, we need delete its external component from both providedComponents map set and appTouchedCompoents map set.

* fix: new deployed app registers externalComponents automatically

since the new deployed app will try to register their externalComponent when the  `initializeApp` method of AppManager is called. This is not expected behavior. We introduce a new parameter `addToProvidedComponents` for the method `registerComponent` to handle the above problem. Without specifying `registerComponent` to true, the app only "declares" it touched the external component when it is initialized. Only if the `enableApp` method is called, the external component will truly added to providedComponents map set, which means we can access it in the `Game Center`.

* Add new location to the external components called MODAL (#137)

* Add new location to external components
* MODAL (new)

* update enum ExternalComponentLocation

* Update external component configration (#134)

* update IWebHooks interface

* Add util randomString

* add AppEmbeddedSDK

* move constants to src/client/constants directory

* separate initListener from call method
* rename initListener to init

* add appId to IExternalComponent interface

* Rename the client sdk to state what it is and improve the documentation

* Add interfaces IUserInfo and IRoomInfo

* Add documentation for the public methods
* getUserInfo
* getRoomInfo

* Rename AppEmbeddedSDK to AppClientEmbeddedSDK
* rename to make sure others can see that it's for client-side
* add the class documentation for the AppClientEmbeddedSDK

* Rename the AppClientEmbeddedSDK methods
* Rename to make sure others can see it's for client-side
* Add documentation for the IClientRoomInfo and IClientInfo interfaces

* Rename external component pieces to be consistent in wording & logic

* remove tests externalComponentBridge

* remove the extra blank line

* fix typos and add necessary blank lines

* fix a grammar error in comments

* Rename names to avoid confusions
* rename IExternalComponentsExtend to IExternalComponentExtend
* rename externalComponents to externalComponent

* Add documentation to register external components method (#156)

* Add documentation to register method

* wording changes for IExternalComponentExtend

* Merge from 'master' and bump to 1.8.0-beta

* Bump to 1.8.0-alpha

* Support multiple external components per app (#150)

* Revert "Rename names to avoid confusions"

This reverts commit d444646.

* support multiple external components per app

* Add error handlers for AppExternalComponentManager

* Add unit tests for two new errors
* ExternalComponentAlreadyTouchedError
* ExternalComponentNotMatchWithAppError

* Add getters for AppExternalComponentManager

* Add unit tests for AppExternalComponentManager
* did some changes to AppExternalComponentManager according to tests

* fix a serious logic error

* compare objects after serialization

* add space before parenttheses

* Modify documentation to state the name unique

* Redesign getExternalComponents
* Rename providedExternalComponents to registeredExternalComponents
* Redesign getExternalComponents

* Remove ExternalComponentAlreadyTouchedError

* overwrite an external component with the same name

* Remove ExternalComponentNotMatchWithAppError
* Because of the caller of the method addExternalComponent is apps-engine. So we can trust the appId provided.
* Always overwrite the externalComponent.appId to the appId via the method addExternalComponent

* Add external components only if it is not empty

* Add a new public method getProvidedComponents

* Make sure the return is an array

* Move external component host logic (#169)

* [ALPHA] Move host logic into apps-engine repo

* Rename EClientEmbeddedSDKActions

* Remove the word `embedded` from client SDK files

* Rename the client SDK to AppsEngineClient

* Redesign external component webhooks (#168)

* Remove IWebHooks
* Remove IWebHooks
* Remove webhooks options from IExternalComponentOptions and redesign it

Introduce state for external components

Add IPreExternalComponentOpenedPrevent handler

Add IPostExternalComponentOpened handler
* add accessors for IPreExternalComponentOpenedPrevent handler
* Add IPostExternalComponentOpened handler

Add IPostExternalComponentClosed handler

Remove IPreExternalComponentOpenedPrevent

* export modules

* Update metadata AppMethod

* Update AppImplements

* Add methods to AppListenerManager

* Remove IWebHooks
* Remove IWebHooks
* Remove webhooks options from IExternalComponentOptions and redesign it

Introduce state for external components

Add IPreExternalComponentOpenedPrevent handler

Add IPostExternalComponentOpened handler
* add accessors for IPreExternalComponentOpenedPrevent handler
* Add IPostExternalComponentOpened handler

Add IPostExternalComponentClosed handler

Remove IPreExternalComponentOpenedPrevent

* export modules

* Update metadata AppMethod

* Update AppImplements

* Add methods to AppListenerManager

* rebase onto move-host-logic

* Remove check methods from event handlers

* Rename a few interfaces

* Rename a few interfaces

* Renamings

* Refactor

* Remove unused files

* Make AppsEngineUIClient use the MESSAGE_ID constant

* Add the command `bundle` for bundling apps engine ui client (#182)

* Add the command `bundle` for bundling SDK

* Bundle sdk before publishing

* Update circleci node version to the same as Rocket.Chat

* Bump beta version

* Bump version

* Definition bump

* Beta version

* Add beta publishing script

* 1.9.0

* 1.10.0-beta

* 1.10.0-alpha

* Bump beta version

* Fix lint

* Fix errors

* Bump alpha version

* Bump definition version

* Bump version to 1.13.0-alpha

* Beta (1.12.0) (#205)

* UIKit (#184)
* Auto create user for app during installation

Co-authored-by: Shiqi Mei <shiqi.mei@lolimay.cn>
Co-authored-by: Upendra Reddy <upendrareddy2511@gmail.com>
Co-authored-by: Diego Sampaio <chinello@gmail.com>
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>

* 1.12.0

* 1.13.0-beta

Co-authored-by: lolimay <lolimay@lolimay.cn>
Co-authored-by: Rodrigo Nascimento <rodrigoknascimento@gmail.com>
Co-authored-by: Shiqi Mei <shiqi.mei@rocket.chat>
Co-authored-by: Shiqi Mei <shiqi.mei@lolimay.cn>
Co-authored-by: Upendra Reddy <upendrareddy2511@gmail.com>
Co-authored-by: Diego Sampaio <chinello@gmail.com>
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
@codecov
Copy link

codecov bot commented Mar 26, 2020

Codecov Report

Merging #248 into alpha will increase coverage by 1.76%.
The diff coverage is 8.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##            alpha     #248      +/-   ##
==========================================
+ Coverage   53.25%   55.02%   +1.76%     
==========================================
  Files          74       82       +8     
  Lines        2704     2866     +162     
  Branches      398      406       +8     
==========================================
+ Hits         1440     1577     +137     
- Misses       1264     1289      +25     
Impacted Files Coverage Ξ”
src/server/managers/AppListenerManager.ts 7.89% <0.00%> (+3.60%) ⬆️
src/server/compiler/AppImplements.ts 100.00% <100.00%> (ΓΈ)
src/server/storage/index.ts 100.00% <0.00%> (ΓΈ)
src/server/compiler/index.ts 100.00% <0.00%> (ΓΈ)
src/server/bridges/index.ts 100.00% <0.00%> (ΓΈ)
src/server/accessors/index.ts 100.00% <0.00%> (ΓΈ)
src/server/marketplace/license/index.ts 100.00% <0.00%> (ΓΈ)
src/server/logging/index.ts 100.00% <0.00%> (ΓΈ)
src/server/errors/index.ts 100.00% <0.00%> (ΓΈ)
src/server/managers/index.ts 100.00% <0.00%> (ΓΈ)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 2a3840c...4887468. Read the comment docs.

@shiqimei shiqimei changed the base branch from master to beta March 26, 2020 15:31
@shiqimei shiqimei force-pushed the omnichannel-agent-related-handlers branch from f23b8cf to d2deb7f Compare March 26, 2020 15:37
@shiqimei shiqimei requested a review from d-gubert March 31, 2020 06:34
@shiqimei shiqimei added the πŸ†• enhancement An enhancement which can be a new feature. label Mar 31, 2020
@d-gubert d-gubert closed this Apr 14, 2020
@d-gubert
Copy link
Member

This was automatically closed when I deleted the previous beta branch. Reopening now.

@d-gubert d-gubert reopened this Apr 17, 2020
@d-gubert d-gubert changed the base branch from beta to alpha April 20, 2020 14:23
@d-gubert d-gubert changed the base branch from alpha to beta April 20, 2020 14:23
@shiqimei shiqimei self-assigned this Apr 20, 2020
* deprecate the old ILivechatRoomClosedHandler and apply IPostLivechatRoomClosed interface instead
@RocketChat RocketChat deleted a comment from CLAassistant Apr 21, 2020
Copy link
Member

@d-gubert d-gubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought a few items to discussion :)

Another question, did the Omnichannel team get to test these events and ensure they fit their needs?

src/definition/livechat/ILivechatRoomClosedHandler.ts Outdated Show resolved Hide resolved
src/definition/livechat/IPostLivechatRoomStarted.ts Outdated Show resolved Hide resolved
src/definition/livechat/IPostLivechatRoomClosed.ts Outdated Show resolved Hide resolved
src/definition/livechat/IPostLivechatAgentUnassigned.ts Outdated Show resolved Hide resolved
src/definition/livechat/IPostLivechatAgentAssigned.ts Outdated Show resolved Hide resolved
src/definition/metadata/AppMethod.ts Outdated Show resolved Hide resolved
src/server/compiler/AppImplements.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
src/definition/livechat/ILivechatContext.ts Outdated Show resolved Hide resolved
@d-gubert d-gubert changed the title Add livechat missing event handlers New livechat event handlers Apr 21, 2020
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Apr 21, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

βœ… lolimay
βœ… d-gubert
❌ sampaiodiego
You have signed the CLA already but the status is still pending? Let us recheck it.

Shiqi Mei and others added 9 commits April 22, 2020 02:20
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
Co-Authored-By: Douglas Gubert <d-gubert@users.noreply.github.com>
@shiqimei
Copy link
Contributor Author

shiqimei commented Apr 21, 2020

Brought a few items to discussion :)

Another question, did the Omnichannel team get to test these events and ensure they fit their needs?

Yeah, I agree. Hi @renatobecker. Can you take a look at these new APIs to make sure they are working?

Below is a minimal app that I do tests locally:

import {
    IAppAccessors,
    IHttp,
    ILogger,
    IPersistence,
    IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { ILivechatEventContext, ILivechatRoom, ILivechatRoomClosedHandler, IPostLivechatAgentAssigned, IPostLivechatAgentUnassigned, IPostLivechatRoomClosed, IPostLivechatRoomStarted } from '@rocket.chat/apps-engine/definition/livechat';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';

export class LivechatTestingApp extends App implements IPostLivechatAgentAssigned, ILivechatRoomClosedHandler, IPostLivechatAgentUnassigned, IPostLivechatRoomStarted, IPostLivechatRoomClosed {
    constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
        super(info, logger, accessors);
    }

    public async executePostLivechatAgentAssigned(data: ILivechatEventContext, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatAgentAssigned', { data });
    }

    public async executePostLivechatAgentUnassigned(data: ILivechatEventContext, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatAgentUnassigned', { data });
    }

    public async executePostLivechatRoomStarted(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatRoomStarted', { data });
    }

    public async executePostLivechatRoomClosed(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatRoomClosed', { data });
    }

    /**
     * @deprecated please prefer using execute executePostLivechatRoomClosed
     */
    public async executeLivechatRoomClosedHandler(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executeLivechatRoomClosedHandler', { data });
    }
}

@d-gubert d-gubert changed the base branch from beta to alpha April 21, 2020 18:54
@renatobecker
Copy link
Contributor

Brought a few items to discussion :)
Another question, did the Omnichannel team get to test these events and ensure they fit their needs?

Yeah, I agree. Hi @renatobecker. Can you take a look at these new APIs to make sure they are working?

Below is a minimal app that I do tests locally:

import {
    IAppAccessors,
    IHttp,
    ILogger,
    IPersistence,
    IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { ILivechatEventContext, ILivechatRoom, ILivechatRoomClosedHandler, IPostLivechatAgentAssigned, IPostLivechatAgentUnassigned, IPostLivechatRoomClosed, IPostLivechatRoomStarted } from '@rocket.chat/apps-engine/definition/livechat';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';

export class LivechatTestingApp extends App implements IPostLivechatAgentAssigned, ILivechatRoomClosedHandler, IPostLivechatAgentUnassigned, IPostLivechatRoomStarted, IPostLivechatRoomClosed {
    constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
        super(info, logger, accessors);
    }

    public async executePostLivechatAgentAssigned(data: ILivechatEventContext, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatAgentAssigned', { data });
    }

    public async executePostLivechatAgentUnassigned(data: ILivechatEventContext, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatAgentUnassigned', { data });
    }

    public async executePostLivechatRoomStarted(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatRoomStarted', { data });
    }

    public async executePostLivechatRoomClosed(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executePostLivechatRoomClosed', { data });
    }

    /**
     * @deprecated please prefer using execute executePostLivechatRoomClosed
     */
    public async executeLivechatRoomClosedHandler(data: ILivechatRoom, read: IRead, http: IHttp, persistence: IPersistence) {
        console.log('executeLivechatRoomClosedHandler', { data });
    }
}

Hi @lolimay sure thing, let me test these new event handlers and give you feedback.

src/definition/livechat/IPostLivechatAgentAssigned.ts Outdated Show resolved Hide resolved
src/definition/livechat/IPostLivechatAgentUnassigned.ts Outdated Show resolved Hide resolved
src/definition/metadata/AppMethod.ts Outdated Show resolved Hide resolved
src/definition/metadata/AppMethod.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
src/server/managers/AppListenerManager.ts Outdated Show resolved Hide resolved
@renatobecker
Copy link
Contributor

@lolimay and @d-gubert,
apart from the comments I left in my review(some typos), I just performed tests simulating the new event handlers and everything is working fine.

Congrats! πŸ₯‡ πŸ‘

Co-Authored-By: Renato Becker <renato.augusto.becker@gmail.com>
@d-gubert d-gubert merged commit af2df37 into alpha Apr 23, 2020
@d-gubert d-gubert deleted the omnichannel-agent-related-handlers branch April 23, 2020 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ†• enhancement An enhancement which can be a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants