Skip to content

Commit

Permalink
feat(ChatlioWidget): Add user info to chatlio widget (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
balzdur authored Dec 13, 2023
1 parent de61672 commit 824566d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/app-builder/src/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type OrganizationDto } from 'marble-api';
export interface Organization {
name: string;
databaseName: string;
exportScheduledExecutionS3: string | undefined;
exportScheduledExecutionS3?: string;
}

export const adaptOrganizationDto = (
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder/src/routes/__builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default function Builder() {
<Sidebar.Link {...linkProps} />
</li>
))}
<ChatlioWidget />
<ChatlioWidget user={user} organization={organization} />
</Sidebar.Nav>
</header>

Expand Down
20 changes: 19 additions & 1 deletion packages/app-builder/src/services/chatlio/ChatlioWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { sidebarLink } from '@app-builder/components';
import { type CurrentUser } from '@app-builder/models';
import { type Organization } from '@app-builder/models/organization';
import { useTranslation } from 'react-i18next';
import { Helpcenter } from 'ui-icons';

export function ChatlioWidget() {
import { getFullName } from '../user';

export function ChatlioWidget({
user,
organization,
}: {
user: CurrentUser;
organization: Organization;
}) {
const { t } = useTranslation(['navigation']);
return (
<>
Expand All @@ -12,6 +22,14 @@ export function ChatlioWidget() {
window._chatlio?.configure?.({
collapsedMode: 'hidden',
});
window._chatlio?.identify?.(
user.actorIdentity.userId ?? `OrgID:${user.organizationId}`,
{
name: getFullName(user.actorIdentity),
email: user.actorIdentity.email,
organization: organization.name,
},
);
window._chatlio?.showOrHide?.();
}}
data-chatlio-widget-button
Expand Down
4 changes: 4 additions & 0 deletions packages/app-builder/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ declare global {
_chatlio?: {
showOrHide?: () => void;
configure?: (config: { [key: string]: unknown }) => void;
identify?: (
id: string,
customData: Record<string, string | undefined>,
) => void;
};
}
}

0 comments on commit 824566d

Please sign in to comment.