Skip to content

Commit

Permalink
Use long polling for the development environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
youneslaa7878 committed Nov 5, 2022
1 parent 7c04ee9 commit 620d199
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
16 changes: 8 additions & 8 deletions environment.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
TELEGRAM_TOKEN: string;
PORT?: number;
}
namespace NodeJS {
interface ProcessEnv {
TELEGRAM_TOKEN: string;
NODE_ENV?: "development" | "production";
PORT?: number;
}
}
export {};
}

export {};
23 changes: 14 additions & 9 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ bot.command("yo", (ctx) => ctx.reply(`Yo ${ctx.from?.username}`));
// Handle all other messages
bot.on("message", (ctx) => ctx.reply("Got another message!"));

// Create the bot's webhooks server
const app = express();
app.use(express.json());
app.use(webhookCallback(bot, "express"));

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Bot listening on port ${PORT}`);
});
if (process.env.NODE_ENV === "production") {
// Use Webhooks for the production server
const app = express();
app.use(express.json());
app.use(webhookCallback(bot, "express"));

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Bot listening on port ${PORT}`);
});
} else {
// Use Long Polling for development
bot.start();
}

0 comments on commit 620d199

Please sign in to comment.