In the world of serverless there is no place for persistence. Even though there are workarounds to get your logs compiled, I thought wouldn’t it be cool to have them on a private discord channel highlighted? And that’s how my interest for writing Ayioo began and extended it to writing a http middleware. In the rest of this post I will give a walk through on how to use Ayioo and AyiooCatch.
Example
First we need our channel id and a token. Hop on to https://discord.com/developers/applications and create a new application.
Once it’s created you can find your token. Now head on to discord and add a server and the application you made to it. You can find resources online if you are stuck in this step.
By default you can find a #default text-channel. World of discord is all about IDs. Right click on #default and select Copy ID.
Yay ⚡ Now we have our token and channel id.
Next we are going to create a very simple express application. Ayioo works with any web framework.
mkdir ayioo-example && cd ayioo-example
Let’s start with initializing npm
npm init -y
We are not going to be doing much in this example other than seeing how Ayioo works. So lets binge install 2 packages. *sniff sniff *
npm install express ayiooo
Let’s make have a app.js file
import express from 'express'
import {Ayioo,AyiooCatch} from 'Ayiooo'
const app = express();
const port = 3001;
Ayioo.configure({
token:"DISCORD_TOKEN",
channelID:"DISCORD_CHANNEL_ID"
})
app.use(AyiooCatch(
{token:`DISCORD_TOKEN`,
channelId:'DISCORD_CHANNEL_ID',instance:true})) //instance property is set to false by default
app.get('/', (req, res) => {
res.send('Hello World!')
Ayioo.log('FROM GET /')
})
app.listen(port, () => {
Ayioo.log(`Example app listening at http://localhost:${port}`)
})
Ayioo is the logger and AyiooCatch is the middleware.
Replace DISCORD_TOKEN and DISCORD_CHANNEL_ID with your token and channel id.
Let spin our server! *Rubbing hands*.
node app.js
And that’s it. Feel free to raise PR or issues if you come across any problems. đźŤ
Future additions
I’m planning to add various features in a sprint over the next few weeks. One of the most interesting one would be to request your log files generated by your server logger from discord. Will keep this post updated. Cheers.