async function getResponse(req: Query, send: SendEventFn) {
send("meta", { content_type: "text/markdown" });
let i = 0;
let message = "";
let totalLength = 0;
while (totalLength < 90000) {
message += chunk(i++);
if (i % 5 == 0) {
totalLength += message.length;
send("text", { text: message });
await sleep(500);
message = "";
}
}
send("done", {});
}
function chunk(i: number) {
return `# Heading ${i}
This is paragraph ${i}.
- List item ${i}.1
- List item ${i}.2
- List item ${i}.3
`;
}
async function getBotSettings(): Promise<BotSettings> {
return {
allow_attachments: true,
expand_text_attachments: true,
introduction_message: "I send an html preview and then say meow",
enable_multi_bot_chat_prompting: true,
};
}
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
type BotSettings = {
allow_attachments?: boolean;
introduction_message?: string;
expand_text_attachments?: boolean;
enable_multi_bot_chat_prompting?: boolean;
};
type Query = {
version: string;
type: "query";
query: {
role: "system" | "user" | "bot";
content: string;
content_type: string;
timestamp: number;
message_id: string;
feedback: { type: "like" | "dislike"; reason?: string }[];
attachments: {
url: string;
content_type: string;
name: string;
parsed_content?: string;
}[];
}[];
message_id: string;
user_id: string;
conversation_id: string;
metadata: string;
language_code: string;
};
type Events = {
meta: { content_type: string };
text: { text: string };
replace_response: { text: string };
suggested_reply: { text: string };
error: { allow_retry?: boolean; text: string };
done: {};
};