Skip to content
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
6 changes: 4 additions & 2 deletions apps/web/app/(app)/[emailAccountId]/channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ function LinkCodeDialog({

const providerName = dialog.provider === "TEAMS" ? "Teams" : "Telegram";
const command = `/connect ${dialog.code}`;
const openBotLabel =
dialog.provider === "TEAMS" ? "Open Teams app" : "Open Telegram bot";

return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
Expand All @@ -635,11 +637,11 @@ function LinkCodeDialog({
<div className="text-xs text-muted-foreground">Command</div>
<CopyInput value={command} />
</div>
{dialog.provider === "TELEGRAM" && dialog.botUrl && (
{dialog.botUrl && (
<div className="pt-1">
<Button asChild size="sm">
<a href={dialog.botUrl} target="_blank" rel="noopener noreferrer">
Open Telegram bot
{openBotLabel}
</a>
</Button>
</div>
Expand Down
19 changes: 19 additions & 0 deletions apps/web/utils/actions/messaging-channels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const { mockEnv, generateMessagingLinkCodeMock } = vi.hoisted(() => ({
mockEnv: {
TEAMS_BOT_APP_ID: "teams-app-id" as string | undefined,
TEAMS_BOT_APP_PASSWORD: "teams-app-password",
TEAMS_BOT_APP_TENANT_ID: undefined as string | undefined,
TELEGRAM_BOT_TOKEN: "telegram-bot-token" as string | undefined,
},
generateMessagingLinkCodeMock: vi.fn(
Expand All @@ -65,6 +66,7 @@ describe("createMessagingLinkCodeAction", () => {

mockEnv.TEAMS_BOT_APP_ID = "teams-app-id";
mockEnv.TEAMS_BOT_APP_PASSWORD = "teams-app-password";
mockEnv.TEAMS_BOT_APP_TENANT_ID = undefined;
mockEnv.TELEGRAM_BOT_TOKEN = "telegram-bot-token";

prisma.emailAccount.findUnique.mockResolvedValue({
Expand All @@ -89,9 +91,26 @@ describe("createMessagingLinkCodeAction", () => {
code: "test-link-code",
provider: "TEAMS",
expiresInSeconds: 600,
botUrl: "https://teams.microsoft.com/l/app/teams-app-id",
});
});

it("includes the Teams tenant id in the Teams bot URL when configured", async () => {
mockEnv.TEAMS_BOT_APP_TENANT_ID = "tenant-id";

const result = await createMessagingLinkCodeAction(
"email-account-1" as any,
{
provider: "TEAMS",
},
);

expect(result?.serverError).toBeUndefined();
expect(result?.data?.botUrl).toBe(
"https://teams.microsoft.com/l/app/teams-app-id?tenantId=tenant-id",
);
});

it("returns an error when Teams is not configured", async () => {
mockEnv.TEAMS_BOT_APP_ID = undefined;

Expand Down
16 changes: 15 additions & 1 deletion apps/web/utils/actions/messaging-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const createMessagingLinkCodeAction = actionClient
provider,
});
const botUrl =
provider === "TELEGRAM" ? await getTelegramBotUrl() : undefined;
provider === "TELEGRAM" ? await getTelegramBotUrl() : getTeamsBotUrl();

return {
code,
Expand Down Expand Up @@ -458,6 +458,20 @@ async function getTelegramBotUrl() {
}
}

function getTeamsBotUrl() {
if (!env.TEAMS_BOT_APP_ID) return;

const url = new URL(
`https://teams.microsoft.com/l/app/${env.TEAMS_BOT_APP_ID}`,
);

if (env.TEAMS_BOT_APP_TENANT_ID) {
url.searchParams.set("tenantId", env.TEAMS_BOT_APP_TENANT_ID);
}

return url.toString();
}

async function syncMessagingFeatureRoute({
messagingChannelId,
routes,
Expand Down
16 changes: 13 additions & 3 deletions apps/web/utils/messaging/chat-sdk/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1834,9 +1834,19 @@ async function handleMessagingLinkCommand({
},
});

await thread.post(
`Connected successfully. You can now chat with your Inbox Zero assistant in this ${provider} DM.`,
);
await postMessagingThreadMessage({
thread,
logger,
message: `Connected successfully. You can now chat with your Inbox Zero assistant in this ${provider} DM.`,
errorLogMessage: "Failed to send messaging link confirmation",
logMeta: {
provider,
emailAccountId: emailAccount.id,
messagingChannelId: messagingChannel.id,
teamId: identity.teamId,
providerUserId: identity.providerUserId,
},
});

return true;
}
Expand Down
Loading