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
2 changes: 1 addition & 1 deletion src/lib/telegram/chat/__tests__/verifyTelegramCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('verifyTelegramCode', () => {
});
expect(clearPendingCode).toHaveBeenCalledWith(thread);
expect(thread.post).toHaveBeenCalledWith(
expect.stringContaining('Welcome to In Process')
expect.stringContaining("You're all set")
);
});
});
2 changes: 1 addition & 1 deletion src/lib/telegram/chat/commands/handleStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const handleStart = async (
artistUsername: string | null,
telegramUsername: string
) => {
const text = `Hello ${artistUsername || telegramUsername}, welcome to In Process! Your telegram has been verified! You can now send photos and captions to post them on In Process.`;
const text = `Hello ${artistUsername || telegramUsername}, Your telegram has been connected! You can now send photos and captions to post them on In Process.`;
await thread.post(text);
};

Expand Down
13 changes: 6 additions & 7 deletions src/lib/telegram/chat/connectTelegramToAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import selectWallets from '@/lib/supabase/in_process_wallets/selectWallets';
import sendCodeHandler from '@/lib/oauth/sendCodeHandler';
import clearPendingEmail from './clearPendingEmail';
import setPendingCode from './setPendingCode';

const INVALID_EMAIL_MESSAGE =
"That doesn't look like a valid email address. Please try again.";
const CODE_SENT_MESSAGE =
"We've sent a 6-digit verification code to that email. Please reply with the code to confirm it's yours.";
import {
TELEGRAM_INVALID_EMAIL_MESSAGE,
TELEGRAM_CODE_SENT_MESSAGE,
} from './consts';

async function connectTelegramToAccount(
thread: Thread<TelegramThreadState>,
text: string
): Promise<void> {
const result = telegramEmailSchema.safeParse(text);
if (!result.success) {
await thread.post(INVALID_EMAIL_MESSAGE);
await thread.post(TELEGRAM_INVALID_EMAIL_MESSAGE);
return;
}

Expand All @@ -43,7 +42,7 @@ async function connectTelegramToAccount(
username: artist?.username ?? null,
});
await clearPendingEmail(thread);
await thread.post(CODE_SENT_MESSAGE);
await thread.post(TELEGRAM_CODE_SENT_MESSAGE);
}

export default connectTelegramToAccount;
20 changes: 20 additions & 0 deletions src/lib/telegram/chat/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ export const TELEGRAM_PENDING_CODE_TTL_MS = 10 * 60 * 1_000;

/** Debounce window for batching media (real Telegram albums and synthesized ungrouped bursts). */
export const MEDIA_GROUP_WINDOW_MS = 10_000;

/** Shown when a Telegram user without a linked account sends any message. */
export const TELEGRAM_NOT_CONNECTED_MESSAGE =
'Welcome to In Process! To get started, please reply with the email you use for In Process so we can connect your Telegram.';

/** Shown when the reply to the email prompt isn't a valid email address. */
export const TELEGRAM_INVALID_EMAIL_MESSAGE =
"That doesn't look like a valid email address. Please try again.";

/** Shown after a verification code has been emailed, whether or not an artist was matched (avoids leaking which emails have an account). */
export const TELEGRAM_CODE_SENT_MESSAGE =
"We've sent a 6-digit verification code to that email. Please reply with the code to confirm it's yours.";

/** Shown when the reply to the code prompt is malformed or Privy rejects the code. */
export const TELEGRAM_INVALID_CODE_MESSAGE =
"That code doesn't look right. Please check your email and try again.";

/** Shown once a Telegram account is successfully connected, whether to an existing or newly created artist. */
export const telegramConnectedMessage = (username: string | null) =>
`You're all set! Your Telegram is now connected to your In Process account${username ? ` (${username})` : ''}. You can now send photos, videos, or YouTube links to create moments.`;
4 changes: 2 additions & 2 deletions src/lib/telegram/chat/handlers/__tests__/onNewMention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('onNewMention', () => {
it('delegates to commandsHandler and returns when handled', async () => {
vi.mocked(commandsHandler).mockResolvedValue(true);

await capturedHandler!(makeThread(), makeMessage({ text: '/start' }));
await capturedHandler!(makeThread(), makeMessage({ text: '/remind' }));

expect(processMediaThread).not.toHaveBeenCalled();
});
Expand All @@ -145,7 +145,7 @@ describe('onNewMention', () => {
await capturedHandler!(thread, makeMessage({ text: 'random text' }));

expect(thread.post).toHaveBeenCalledWith(
'Please send a photo or video with a caption.'
'To post moments, please send a photo or video along with a caption, or share a YouTube link.'
);
});

Expand Down
4 changes: 3 additions & 1 deletion src/lib/telegram/chat/handlers/onNewMention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export function registerOnNewMention(bot: TelegramChatBot) {
return;
}

await thread.post('Please send a photo or video with a caption.');
await thread.post(
'To post moments, please send a photo or video along with a caption, or share a YouTube link.'
);
} catch (error) {
console.error('[telegram-dm] onDirectMessage error:', error);
await thread.post(`❌ something went wrong: ${error}`);
Expand Down
6 changes: 2 additions & 4 deletions src/lib/telegram/chat/promptTelegramEmail.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Thread } from 'chat';
import type { TelegramThreadState } from './telegramThreadState';
import setPendingEmail from './setPendingEmail';

const NOT_CONNECTED_MESSAGE =
"We couldn't find an In Process account connected to this Telegram yet. To connect it, please reply with the email address you use for In Process.";
import { TELEGRAM_NOT_CONNECTED_MESSAGE } from './consts';

async function promptTelegramEmail(
thread: Thread<TelegramThreadState>
): Promise<void> {
await thread.post(NOT_CONNECTED_MESSAGE);
await thread.post(TELEGRAM_NOT_CONNECTED_MESSAGE);
await setPendingEmail(thread);
}

Expand Down
20 changes: 9 additions & 11 deletions src/lib/telegram/chat/verifyTelegramCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import getOrCreateArtist from '@/lib/artists/getOrCreateArtist';
import { upsertArtists } from '@/lib/supabase/in_process_artists/upsertArtists';
import clearPendingCode from './clearPendingCode';
import type { PendingCode } from './getPendingCode';

const INVALID_CODE_MESSAGE =
"That code doesn't look right. Please check your email and try again.";
const WELCOME_MESSAGE =
"Welcome to In Process! We've created your account and connected your Telegram. You can now send photos and videos to publish moments.";
import {
TELEGRAM_INVALID_CODE_MESSAGE,
telegramConnectedMessage,
} from './consts';

async function verifyTelegramCode(
thread: Thread<TelegramThreadState>,
Expand All @@ -22,7 +21,7 @@ async function verifyTelegramCode(
): Promise<void> {
const result = telegramCodeSchema.safeParse(text);
if (!result.success) {
await thread.post(INVALID_CODE_MESSAGE);
await thread.post(TELEGRAM_INVALID_CODE_MESSAGE);
return;
}

Expand All @@ -33,27 +32,26 @@ async function verifyTelegramCode(
result.data
);
} catch {
await thread.post(INVALID_CODE_MESSAGE);
await thread.post(TELEGRAM_INVALID_CODE_MESSAGE);
return;
}

await clearPendingCode(thread);

const connectedMessage = telegramConnectedMessage(pending.username);
if (!pending.artistId) {
const walletAddress = await ensurePrivySocialWallet(authResult);
const artist = await getOrCreateArtist({
address: walletAddress as Address,
type: 'privy',
});
await upsertArtists({ id: artist.artistId, telegram: telegramUsername });
await thread.post(WELCOME_MESSAGE);
await thread.post(connectedMessage);
return;
}

await upsertArtists({ id: pending.artistId, telegram: telegramUsername });
await thread.post(
`You're all set! Your Telegram is now connected to your In Process account${pending.username ? ` (${pending.username})` : ''}. You can now send photos and videos to publish moments.`
);
await thread.post(connectedMessage);
}

export default verifyTelegramCode;
Loading