Skip to content

Commit

Permalink
Add support for new event PARTICIPANT_INVITED (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
agarwhi authored Dec 15, 2024
1 parent ef5b28c commit 4ff2041
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ const EVENT_CONTENT_TYPE: {
DELIVERED_RECEIPT: "application/vnd.amazonaws.connect.event.message.delivered",
PARTICIPANT_JOINED: "application/vnd.amazonaws.connect.event.participant.joined",
PARTICIPANT_LEFT: "application/vnd.amazonaws.connect.event.participant.left",
PARTICIPANT_INVITED: "application/vnd.amazonaws.connect.event.participant.invited",
TRANSFER_SUCCEEDED: "application/vnd.amazonaws.connect.event.transfer.succeed",
TRANSFER_FAILED: "application/vnd.amazonaws.connect.event.transfer.failed",
CONNECTION_ACKNOWLEDGED: "application/vnd.amazonaws.connect.event.connection.acknowledged",
Expand Down Expand Up @@ -618,6 +619,29 @@ chatSession.onTyping(event => {
Subscribes an event handler that triggers whenever a `application/vnd.amazonaws.connect.event.typing` event is created by any participant.
The `data` field has the same schema as `chatSession.onMessage()`.

##### `chatSession.onParticipantInvited()`

```js
/**
* Subscribes an event handler that triggers whenever a "application/vnd.amazonaws.connect.event.participant.invited" event is created by any participant.
* @param {
AbsoluteTime?: string,
ContentType?: string,
Type?: string,
ParticipantId?: string,
DisplayName?: string,
ParticipantRole?: string,
InitialContactId?: string
} event.data
*/
chatSession.onParticipantInvited(event => {
const { chatDetails, data } = event;
if (data.ParticipantRole === "AGENT") {
// ...
}
});
```

##### `chatSession.onParticipantIdle()`

```js
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const CHAT_EVENTS = {
MESSAGE_METADATA: "MESSAGEMETADATA",
PARTICIPANT_IDLE: "PARTICIPANT_IDLE",
PARTICIPANT_RETURNED: "PARTICIPANT_RETURNED",
PARTICIPANT_INVITED: "PARTICIPANT_INVITED",
AUTODISCONNECTION: "AUTODISCONNECTION",
DEEP_HEARTBEAT_SUCCESS: "DEEP_HEARTBEAT_SUCCESS",
DEEP_HEARTBEAT_FAILURE: "DEEP_HEARTBEAT_FAILURE",
Expand Down Expand Up @@ -104,6 +105,7 @@ export const CONTENT_TYPE = {
deliveredReceipt: "application/vnd.amazonaws.connect.event.message.delivered",
participantIdle: "application/vnd.amazonaws.connect.event.participant.idle",
participantReturned: "application/vnd.amazonaws.connect.event.participant.returned",
participantInvited: "application/vnd.amazonaws.connect.event.participant.invited",
autoDisconnection: "application/vnd.amazonaws.connect.event.participant.autodisconnection",
chatRehydrated: "application/vnd.amazonaws.connect.event.chat.rehydrated"
};
Expand All @@ -114,6 +116,7 @@ export const CHAT_EVENT_TYPE_MAPPING = {
[CONTENT_TYPE.deliveredReceipt]: CHAT_EVENTS.INCOMING_DELIVERED_RECEIPT,
[CONTENT_TYPE.participantIdle]: CHAT_EVENTS.PARTICIPANT_IDLE,
[CONTENT_TYPE.participantReturned]: CHAT_EVENTS.PARTICIPANT_RETURNED,
[CONTENT_TYPE.participantInvited]: CHAT_EVENTS.PARTICIPANT_INVITED,
[CONTENT_TYPE.autoDisconnection]: CHAT_EVENTS.AUTODISCONNECTION,
[CONTENT_TYPE.chatRehydrated]: CHAT_EVENTS.CHAT_REHYDRATED,
default: CHAT_EVENTS.INCOMING_MESSAGE,
Expand Down
4 changes: 4 additions & 0 deletions src/core/chatSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class ChatSession {
this.controller.subscribe(CHAT_EVENTS.PARTICIPANT_RETURNED, callback);
}

onParticipantInvited(callback) {
this.controller.subscribe(CHAT_EVENTS.PARTICIPANT_INVITED, callback);
}

onAutoDisconnection(callback) {
this.controller.subscribe(CHAT_EVENTS.AUTODISCONNECTION, callback);
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/chatSession.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe("chatSession", () => {
const cb12 = jest.fn();
const cb13 = jest.fn();
const cb14 = jest.fn();
const cb15 = jest.fn();

session.onParticipantIdle(cb1);
session.onParticipantReturned(cb2);
Expand All @@ -104,9 +105,11 @@ describe("chatSession", () => {
session.onDeepHeartbeatSuccess(cb12);
session.onDeepHeartbeatFailure(cb13);
session.onChatRehydrated(cb14);
session.onParticipantInvited(cb15);

controller._forwardChatEvent(CHAT_EVENTS.PARTICIPANT_IDLE, eventData);
controller._forwardChatEvent(CHAT_EVENTS.PARTICIPANT_RETURNED, eventData);
controller._forwardChatEvent(CHAT_EVENTS.PARTICIPANT_INVITED, eventData);
controller._forwardChatEvent(CHAT_EVENTS.AUTODISCONNECTION, eventData);
controller._forwardChatEvent(CHAT_EVENTS.INCOMING_MESSAGE, eventData);
controller._forwardChatEvent(CHAT_EVENTS.INCOMING_TYPING, eventData);
Expand Down Expand Up @@ -136,6 +139,7 @@ describe("chatSession", () => {
expect(cb12).toHaveBeenCalled();
expect(cb13).toHaveBeenCalled();
expect(cb14).toHaveBeenCalled();
expect(cb15).toHaveBeenCalled();
});

test('events', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ declare namespace connect {
*/
onParticipantReturned(handler: (event: ChatTypingEvent) => void): void;


/**
* Subscribes an event handler that triggers whenever a "application/vnd.amazonaws.connect.event.participant.invited" event is received.
* @param handler The event handler.
*/
onParticipantInvited(handler: (event: ChatTypingEvent) => void): void;

/**
* Subscribes an event handler that triggers whenever a "application/vnd.amazonaws.connect.event.participant.autodisconnection" event is created by any participant.
* @param handler The event handler.
Expand Down

0 comments on commit 4ff2041

Please sign in to comment.