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

How do you use this for your own webex bot ? #25

Open
sharikav opened this issue Sep 22, 2022 · 1 comment
Open

How do you use this for your own webex bot ? #25

sharikav opened this issue Sep 22, 2022 · 1 comment

Comments

@sharikav
Copy link

I want the user to be able to enter a file and write some code to process it, is that possible?

@valgaze
Copy link
Owner

valgaze commented Sep 23, 2022

Hey @sharikav

For sure-- just use the <@fileupload> keyword on the handler

See this repo for a complex example using spreadsheets (*.xlsx) & fallback for other file types: https://github.com/valgaze/speedybot-superpowers

But for something simple, ex

import { BotHandler, BotInst, Trigger, $ } from "speedybot";
const handlers: BotHandler[] = [
  {
    keyword: "<@fileupload>",
    async handler(bot, trigger) {
      const $bot = $(bot);
      // take 1st file uploaded, note this is just a URL which requires auth to retrieve
      const [file] = trigger.message.files;

      const filePayload = await $bot.getFile(file, {
        responseType: "arraybuffer",
      });

      const { data, extension, fileName, type, markdownSnippet } = filePayload;

	  // Do something w/ data here
	  // data: raw file data if relevant
	  // extension: the file's extension
	  // filename: the file's name on harddisk (however uploaded)
	  // type: the file's media type from content header, ex "image/jpeg"
    },
    helpText: `Special handler that's fired when the user uploads a file to your bot (by default supports json/csv/txt.) If you use the word "convert", it will convert a spreadsheet (.xlsx) file to an html preview`,
  },
];

export default handlers;

I'm not hard to find-- hit me up if any trouble

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants