Discord:
Discord.js is a powerful Node.js module that helps one to interact with the Discord API.
The Tensorflow model gets loaded into the app once the app is ready(online) using the client.once("ready") as an async function.
Loading the model once helps speed the bot as loading the model takes time.
Next we use client.on("message create") as an async function in which we retreive the text of the message(barring the message id, server id which comes with the discord API request) and send it through the model to predict.
Each prediction is pushed onto an array, which later helps us
articulate the warning message mentioning the parameters for deletion of the message.
If the length of the pred array is not zero, we can safely delete the message using message.delete().
Slack:
Slack does not have a "ready" event similar to discord as the bolt.js framework is under development. Hence, we need to load the Tensorflow model everytime we receive a message.
Next we use async function that runs when the event occurred is "message". We load the model, after which we retreive the text of the message(barring the message id, server id which comes with the Slack API request) and send it through the model to predict.
Each prediction is pushed onto an array, which later helps us
articulate the warning message mentioning the parameters for deletion of the message.
If the length of the pred array is not zero, we can safely delete the message using client.chat.delete() as provided by Bolt.js .
Deployment
We used Heroku for publishing the app.
Heroku was used because it provides a free 24/7 Hobby plan which was preferable to use for our demo. The problem with Heroku is that the free dynos used may become idle, if the app remains unused for 24 hours.