Skip to content

Commit

Permalink
refac: move sendmessage into its own dir
Browse files Browse the repository at this point in the history
  • Loading branch information
chuangcaleb committed Apr 27, 2024
1 parent eab082f commit 78426c8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ data/
*.db
*.db-journal

.vscode/
.vscode/
**mock**
1 change: 1 addition & 0 deletions src/bot/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./admin.js";
export * from "./language.js";
export * from "./unhandled.js";
export * from "./welcome.js";
export * from "./sendmessage/index.js";
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Conversation, createConversation } from "@grammyjs/conversations";
import { Context } from "~/bot/context.js";
import { i18n } from "~/bot/i18n.js";
import { REGISTRY } from "./mock-data.js";

Check failure on line 4 in src/bot/features/sendmessage/sendmessage.conversation.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unable to resolve path to module './mock-data.js'

export const SENDMESSAGE_CONVERSATION = "sendmessage";

Expand All @@ -9,28 +10,20 @@ export function sendmessageConversation() {
async (conversation: Conversation<Context>, ctx: Context) => {
await conversation.run(i18n);

// Get message
await ctx.reply("Please tell me the message you want to send");

ctx = await conversation.waitFor("message::bold", {
const messageCtx = await conversation.waitFor("message::bold", {
otherwise: async (ctxx) => {
ctxx.reply("please send bold");
await conversation.skip({ drop: true });
},
});
ctx.reply(ctx.message?.text as string);
const message = messageCtx.message?.text ?? "";

// while (true) {
// ctx = await conversation.wait();

// if (ctx.has("message:text")) {
// ctx.chatAction = "typing";
// await conversation.sleep(1000);

// await ctx.reply(`Hello, ${ctx.message.text}!`);
// } else {
// await ctx.reply("Please send me your name");
// }
// }
// Get targets
await ctx.reply("Please select the students");
ctx.api.sendMessage(REGISTRY.Chuang, message);
},
SENDMESSAGE_CONVERSATION
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Composer } from "grammy";
import type { Context } from "~/bot/context.js";
import { logHandle } from "~/bot/helpers/logging.js";
import { SENDMESSAGE_CONVERSATION } from "../conversations/sendmessage.conversation.js";
import { SENDMESSAGE_CONVERSATION } from "./sendmessage.conversation.js";

const composer = new Composer<Context>();

Expand Down
4 changes: 2 additions & 2 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { i18n, isMultipleLocales } from "~/bot/i18n.js";
import { updateLogger } from "~/bot/middlewares/index.js";
import { config } from "~/config.js";
import { logger } from "~/logger.js";
import { sendmessageConversation } from "./conversations/sendmessage.conversation.js";
import { sendmessageFeature } from "./features/sendmessage.js";
import { sendmessageConversation } from "./features/sendmessage/sendmessage.conversation.js";
import { sendmessageFeature } from "./features/sendmessage/sendmessage.js";

type Options = {
sessionStorage?: StorageAdapter<SessionData>;
Expand Down

0 comments on commit 78426c8

Please sign in to comment.