ProTechMe PDF conversion
ProTechMe is a chat bot to collect information for protective order. Read more here.
The ProTechMe PDF conversion is a Node.js application that gets messages (JSON data) from a ProTechMe chat bot and converts the conversation into a PDF file.
Table of content
- Parsing of JSON data
- Due to the use of jsPDF library, format the messages to:
- Separate questions from the bot and answers from the user
- Build the content of the document line by line
- Coloring the questions and answers differently
- Writing a PDF document
- Returning a link to the downlodable document
- Sending out an email with the PDF document as an attachement (if applicable)
- Deleting the document after 5 minutes
/: The homepage will display information (most likely from the repository Readme file)
/create-pdf: The route requested by the chat bot accompanied by JSON data in the body of the request. The text of the chat messages in the JSON data will be written into a PDF document. Note: depending on the previous message in the conversation, the chat bot will receive back a (temporarily) link to the downloadable PDF or the link and an email will be sent to an email address communicated by the user in the conversation (with the PDF file as an attachment).
/file/:name: The route used to serve the (temporarily) downloadable PDF file
- Make sure you have a version of Node greater than 4 installed with the command
$ node -v, and have npm installed.
- Clone the repository
$ git clone firstname.lastname@example.org:TechForJustice/protechmepdfconversion.git.
- Install all dependencies locally with
- Run it locally with
node index.js local
The application is hosted on Heroku. Deploying it is as easy as
git push heroku master.
A few configuration variables are set that are used by both the application and the chatbot.
Those variables are:
A password for encryption purpose (
CRYPTO_SECRET), credentials for the emails' sender (
EMAIL_PASSWORD), an address to send an email for assistance (
- When working locally, you can set them using
$ export VARIABLE_NAME=VARIABLE_VALUE.
- For the application, the easiest way to edit those are via Heroku's dashboard:
- Access the Heroku dashboard
Settingstab (assuming you have the credentials to do so),
- On the page, look for
- Click on
Reveal config variables. There you can edit existing variables or add new ones if needed.
index.js- Defines the routes of the application and especially
/create-pdfthat is called by the bot with JSON data to create a PDF. Note: the PDF file is currently only store for 5 minutes.
parseMessages.js- Takes in the messages received from the bots and shape them so they can be written to a file using the jsPDF library.
bot.js- Keeps track of the code for the chat bot Node module that post a request to the
/create-pdfroute. Note: The configuration variables are missing on purpose. DO NOT COMMIT THEM.
mailer.js- Uses the
nodemailerpackage to send out emails
utils.js- Uses the
cryptoNode module to keep the user email address anonymous while it is sent between the chatbot and this application
tmp/- Folder to temporarily store the PDF files (the app expects this directory to be present)
views/readme.html- An html template for the application homepage. It contains the info on the repo's Readme and was created using the package markdown-to-html.
packages.json- Defines the dependencies
app.json- Metadata for the application
Procfile- Metadata for Heroku
Useful links for contributors