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

Install sequence #1

Open
jwinkle opened this issue Mar 5, 2016 · 1 comment
Open

Install sequence #1

jwinkle opened this issue Mar 5, 2016 · 1 comment

Comments

@jwinkle
Copy link

jwinkle commented Mar 5, 2016

Hi bjester: We're a University research group looking to use slack with latex and after I've installed node and slacktex, I'm unsure what has to change in the config file. If I understand correctly, image files are generated via the local latex package, stored on a remote host then loaded into the slack thread using HTTP. So in the config file "default.json" we need to sub "example.com" with "myuniv.edu/mysubdomain/mystoragefolder" ? Basically not sure what to set for all of the "server" parameters in our case or even "latex" -- would set "command" to "/latex" for example? Thanks for any help here, we would love to share latex formulas in our threads. jwinkle

@bjester
Copy link
Owner

bjester commented Mar 5, 2016

It's been a while since I set this up, so I'm going to list out everything that I can remember to cover all the bases. You'll need to set up two things in Slack: a slash command and a custom incoming webhook.

The slash command tells slack that when someone types something like /latex f(x,y) = \frac{x}{y} and hits enter, it sends some information to the url you configured in slack. So if you set the slash command url in slack to http://example.com:8000/latex then you'll want the following options in the server config to look like:

    "host": "example.com",
    "port": 8000,
    "request_path": "/latex",

When you set up the slash command in slack, it will also have a field for a token. Whatever value this field is you'll want to put in the token field in the slack config. So for a slash command of /latex, maybe that looks something like:

    "token": "e9T1Qw5YMztq21gVf0dw83La",
    "command": "/latex"

So when someone enters their slash latex command, slack makes a request to the url you configured, and this code generates the PNG image and puts the image in output_dir. So if I set "output_dir": "/home/bjester/slacktex/images", then I should see images in that directory when slash commands are sent.

The next part requires that you also have a web server installed, like Apache or nginx. After the PNG image is created, this code will POST back to slack. This is where you'll need to configure the Incoming Webhook in slack. For the most part, you don't need to worry about the configuration options in slack for this. Set a name, description, perhaps add an image and copy the webhook url that it gives you. Put that url into the webhook_url value of the slack config. When it POST's back to slack, it sends a url to the image which gets unfurled in slack. That url depends on the output_path option. So if I had my webserver root for example.com set to /home/bjester/slacktex, then I want the output path to be /images. Then the url of the images would be something like http://example.com/images/e01096b9ffe3f416157f6ec46c467725.png.

The full config would then be:

{
  "server": {
    "host": "example.com",
    "port": 8000,
    "request_path": "/latex",
    "output_path": "/images",
    "output_dir": "/home/bjester/slacktex/images",
    "temp_dir": "/tmp"
  },
  "slack": {
    "token": "e9T1Qw5YMztq21gVf0dw83La",
    "command": "/latex",
    "webhook_url": "https://hooks.slack.com/services/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"
  },
  "png": {
    "bin": "/usr/bin/dvipng"
  },
  "tex": {
    "bin": "/usr/bin/latex",
    "template": "./resource/template.tex"
  }
}

A couple other things:

  • It doesn't matter where this code lives
  • The port must be unused and accessible; a firewall would probably be configured to block access to a previously unused port
  • This code must be able to write to output_dir and temp_dir
  • You'll need dvipng and latex installed so that the bin config options actually map to executables
  • All of this assumes you'll be running this on linux

I hope this helps and that slack works out for you. Slack never really caught on with my university's physics group.

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

No branches or pull requests

2 participants