Coder Social home page Coder Social logo

Fastify example about examples HOT 11 CLOSED

grammyjs avatar grammyjs commented on September 4, 2024
Fastify example

from examples.

Comments (11)

gomez-git avatar gomez-git commented on September 4, 2024 1

@gomez-git could you take a look at #30 and leave an approval there if you could make it work?

I think about this one

import { Bot, webhookCallback } from 'grammy';
import fastify from 'fastify';
import ngrok from '@ngrok/ngrok';

const { BOT_TOKEN, PORT, SECRET_TOKEN } = process.env;

const bot = new Bot(BOT_TOKEN);

bot.on('message:text', (ctx) => ctx.reply(ctx.message.text));

const server = fastify();

server.post('/webhook', webhookCallback(bot, 'fastify', { secretToken: SECRET_TOKEN })); 

server.listen({ port: +PORT }, async (err, address) => {
  if (err) {
    console.error(err);
    process.exit(1);
  }
  const url = await ngrok.connect(+PORT);
  await bot.api.setWebhook(`${url}/webhook`, { secret_token: SECRET_TOKEN });
});

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024 1

Yes, let's do that. @AbbassAlmusawi could you update your code in #30 with the above package? I'll merge after that.

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024

@gomez-git could you take a look at #30 and leave an approval there if you could make it work?

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024

Perhaps we should use the official package https://www.npmjs.com/package/@ngrok/ngrok instead?

from examples.

gomez-git avatar gomez-git commented on September 4, 2024

Perhaps we should use the official package https://www.npmjs.com/package/@ngrok/ngrok instead?

I use it in my snippet, isn't it?

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024

No. You're using https://github.com/bubenshchykov/ngrok. See https://t.me/grammyjs/166618.

from examples.

rojvv avatar rojvv commented on September 4, 2024

@KnorpelSenf They are importing @ngrok/ngrok in #29 (comment), 3rd line.

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024

Oh what

from examples.

KnorpelSenf avatar KnorpelSenf commented on September 4, 2024

I'm blind

from examples.

gomez-git avatar gomez-git commented on September 4, 2024

Dockerfile

FROM node:18-alpine

WORKDIR /usr/src

COPY ./package*.json ./

EXPOSE 443

RUN npm ci

COPY . ./

CMD ["ts-node", "fastify-ngrok-webhook.ts"]

.dockerignore

node_modules

command

docker build --tag grammy_fastify_example .
docker run --detach \
  --name grammy_fe \
  -e BOT_TOKEN='' \
  -e PORT='' \
  -e SECRET_TOKEN='' \
  grammy_fastify_example

from examples.

AbbassAlmusawi avatar AbbassAlmusawi commented on September 4, 2024

Done, please see #30 and tell me if there are any mistakes of suggestions

from examples.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.