Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "chunk" argument must be one of type string or Buffer. Received type object #2

Open
sparkyfen opened this issue Aug 25, 2022 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sparkyfen
Copy link

sparkyfen commented Aug 25, 2022

The caption command fails below in CFWorker with error:

  (error) TypeError: The "chunk" argument must be one of type string or Buffer. Received type object
    at new n2 (worker.js:16656:23)
    at worker.js:17181:95
    at A.write (worker.js:17182:10)
    at A.end (worker.js:17216:144)
    at s.addPart (worker.js:20412:73)
    at S (worker.js:20325:21)
    at async worker.js:20313:22
    at async Promise.all (index 2)
    at async _ (worker.js:20318:16)
    at async s.callApi (worker.js:20362:30)

Borrowed from https://github.com/telegraf/telegraf/blob/302a46d144993be7a95c5864c87a8d7b79230d1e/docs/examples/keyboard-bot.js#L83

import { Telegraf, Markup } from 'telegraf';
import { Application, Router } from '@cfworker/web';
import createTelegrafMiddware from 'cfworker-middware-telegraf';
import { DEFAULT_CORS_HEADERS } from './utils';

const bot = new Telegraf(TELEGRAM_API_TOKEN);

//... other commands here

bot.command('caption', (ctx) => {
  return ctx.replyWithPhoto({ url: 'https://picsum.photos/200/300/?random' },
    {
      caption: 'Caption',
      parse_mode: 'Markdown',
      ...Markup.inlineKeyboard([
        Markup.button.callback('Plain', 'plain'),
        Markup.button.callback('Italic', 'italic')
      ])
    }
  )
});

const router = new Router();

// Simple CORS middleware.
const cors = async ({ res }, next) => {
  for (const HEADER_KEY in DEFAULT_CORS_HEADERS) {
    res.headers.set(HEADER_KEY, DEFAULT_CORS_HEADERS[HEADER_KEY]);
  }
  await next();
};

router.post(`/${TELEGRAM_SECRET_PATH}`, createTelegrafMiddware(bot));
new Application().use(cors).use(router.middleware).listen();

Any suggestions?

@Tsuk1ko Tsuk1ko added bug Something isn't working help wanted Extra attention is needed labels Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants