Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActivityType } from './../../../../src/types/DirectLineTypes';
import { StateKey } from './../../../../src/types/ic3/IC3AdapterState';
import { TelemetryEvents } from './../../../../src/types/ic3/TelemetryEvents';
import createEgressTypingActivityMiddleware from './../../../../src/ic3/enhancers/egress/createEgressTypingActivityMiddleware';
import { MessageTag } from './../../../../src/types/ic3/MessageTag';

describe('createEgressTypingActivityMiddleware test', () => {
let globalMicrosoftBefore;
Expand Down Expand Up @@ -65,7 +66,8 @@ describe('createEgressTypingActivityMiddleware test', () => {
}
createEgressTypingActivityMiddleware()({getState: mockGetState})(next)(activity);
expect(indicateTypingStatusMock).toHaveBeenCalledWith('Typing', {
imdisplayname: StateKey.UserDisplayName
imdisplayname: StateKey.UserDisplayName,
tag: "public"
});
expect(sendMessageToBotMock).toHaveBeenCalledWith(StateKey.BotId, {
payload: '{"isTyping":true}'
Expand All @@ -76,4 +78,25 @@ describe('createEgressTypingActivityMiddleware test', () => {
CustomProperties: expect.anything()
});
});

test('should indicate typing status, and pass tag', () => {
const activity = {
type: ActivityType.Typing,
channelData: { tags: ['private'] }
}
createEgressTypingActivityMiddleware()({getState: mockGetState})(next)(activity);
expect(indicateTypingStatusMock).toHaveBeenCalledWith('Typing', {
imdisplayname: StateKey.UserDisplayName,
tag: 'private'
});

expect(sendMessageToBotMock).toHaveBeenCalledWith(StateKey.BotId, {
payload: '{"isTyping":true}'
});
expect(logClientSdkTelemetryEventSpy).toHaveBeenCalledWith('DEBUG', {
Event: TelemetryEvents.SEND_TYPING_SUCCESS,
Description: `Adapter: Successfully sent a typing indication`,
CustomProperties: expect.anything()
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,19 @@ describe('createPatchFromRoleAndNameMiddleware test', () => {
expect(result).toBe('next');
expect(next).toHaveBeenCalledWith({...activity});
});

test('should call next with correct params and include tag', () => {
const getState = (key) => key === StateKey.UserId ? 'userId' : key === StateKey.UserDisplayName ? 'userName' : null;
const activity = {
from: {
id: 'userIdActivity',
name: 'activityName',
role: Role.Channel,
tag: 'private'
}
}
const result = createPatchFromRoleAndNameMiddleware()({ getState })(next)(activity);
expect(result).toBe('next');
expect(next).toHaveBeenCalledWith({...activity});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,26 @@ describe('createTypingMessageToDirectLineActivityMapper test', () => {
}
expect(result).toEqual(expectedResult);
});

test('should pass tag with sender', async () => {
spyOn(Date.prototype, 'toISOString').and.returnValue('dateString');
spyOn(uniqueId, 'default').and.returnValue('uniqueId');
const conversation = { id: 'tesConvId' };
const getState = () => conversation;
const message = {
messageType: 'Typing',
timestamp: new Date(),
sender: { displayName: 'displayName', id: 'senderId', tag: 'private' }
};
const result = await createTypingMessageToDirectLineActivityMapper({ getState })()(message);
const expectedResult = {
channelId: IC3_CHANNEL_ID,
conversation,
from: { id: message.sender.id, name: message.sender.displayName, tag: message.sender.tag },
id: 'uniqueId',
timestamp: 'dateString',
type: ActivityType.Typing
}
expect(result).toEqual(expectedResult);
});
});
13 changes: 12 additions & 1 deletion src/ic3/enhancers/egress/createEgressTypingActivityMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function isInternalActivity(activity: IC3DirectLineActivity): boolean {
return activity.channelData && activity.channelData.tags && activity.channelData.tags.includes(MessageTag.Private);
}

function getTags(isInternalActivity: boolean): string {
if (isInternalActivity)
{
return MessageTag.Private;
}
else {
return "public";
}
}

export default function createEgressTypingActivityMiddleware(): EgressMiddleware<
IC3DirectLineActivity,
IC3AdapterState
Expand All @@ -32,7 +42,8 @@ export default function createEgressTypingActivityMiddleware(): EgressMiddleware
}

conversation.indicateTypingStatus(Microsoft.CRM.Omnichannel.IC3Client.Model.TypingStatus.Typing, {
imdisplayname: getState(StateKey.UserDisplayName) || activity.from.name || ''
imdisplayname: getState(StateKey.UserDisplayName) || activity.from.name || '',
tag: getTags(isInternalActivity(activity))
});

const botIds = getState(StateKey.BotId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function createPatchFromRoleAndNameMiddleware(): IngressMiddlewar
> {
return ({ getState }) => next => (activity: IC3DirectLineActivity) => {
const {
from: { id, name, role }
from: { id, name, role, tag }
} = activity;

const userId = getState(StateKey.UserId);
Expand All @@ -26,7 +26,8 @@ export default function createPatchFromRoleAndNameMiddleware(): IngressMiddlewar
from: {
id,
role: patchedRole,
name: (patchedRole === Role.User && getState(StateKey.UserDisplayName)) || name
name: (patchedRole === Role.User && getState(StateKey.UserDisplayName)) || name,
tag
}
}
return next(patchedActivity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function createTypingMessageToDirectLineActivityMapper({
}

const {
sender: { displayName: name, id },
sender: { displayName: name, id, tag },
timestamp
} = message;

Expand All @@ -43,7 +43,8 @@ export default function createTypingMessageToDirectLineActivityMapper({
conversation: { id: conversation.id },
from: {
id,
name
name,
tag
},
id: uniqueId(),
timestamp: timestamp.toISOString(),
Expand Down
1 change: 1 addition & 0 deletions src/types/DirectLineTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface IDirectLineActivity {
id: string;
name?: string;
role?: Role;
tag?: string;
};
id?: string;
suggestedActions?: SuggestedActions;
Expand Down
1 change: 1 addition & 0 deletions src/types/ic3/external/Model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ declare namespace Microsoft.CRM.Omnichannel.IC3Client.Model {
displayName: string;
id: string;
type: PersonType;
tag?: string;
}
}

Expand Down