Quick Start Guide

This step-by-step guide will show you how to create an application that sends a Discord invitation email when a webhook is called.

1. Installation

Run the following command in a console to install the MESG Engine:

bash <(curl -fsSL https://mesg.com/install)

You can also install it manually by following this guide.

2. Run the MESG Engine

MESG Engine runs as a daemon. To start it, execute:

mesg-core start

3. Deploy the services

You need to deploy every service your application is using.

In this guide, the application is using 2 services.

Start by deploying the webhook service:

mesg-core service deploy https://github.com/mesg-foundation/service-webhook

Deploy the invite discord service:

mesg-core service deploy https://github.com/mesg-foundation/service-discord-invitation

Once the service is deployed, the console displays its id. This id is a unique way for the application to connect to the right service through the MESG Engine. You'll need to use them inside the application.

4. Create the application

Now when the services are up and running, let's create the application.

The application is using NodeJS and NPM.

Let's init the app and install the MESG JS library.

Create and move your terminal to a folder that will contain the application. Then run:

npm init && npm install --save mesg-js

Now, create an index.js file and with the following code:

const mesg = require('mesg-js').application()

const email = '__YOUR_EMAIL_HERE__' // To replace by your email
const sendgridAPIKey = '__SENDGRID_API_KEY__' // To replace by your SendGrid API key. See https://app.sendgrid.com/settings/api_keys

  serviceID: 'webhook',
  eventFilter: 'request'
  .on('data', async (event) => {
    console.log('webhook event received')
    try {
      const result = await mesg.executeTaskAndWaitResult({
        serviceID: 'discord-invitation',
        taskKey: 'send',
        inputData: JSON.stringify({ email, sendgridAPIKey })
      if (result.outputKey !== 'success') {
        const message = JSON.parse(result.outputData).message
        console.error('an error occurred while sending the invitation: ', message)
      console.log('discord invitation send to:', email)
    } catch (error) {
      console.error('an error occurred while executing the send task:', error.message)
  .on('error', (error) => {
    console.error('an error occurred while listening the request events:', error.message)

console.log('application is running and listening for events')

Don't forget to replace the values __YOUR_EMAIL_HERE__ and __SENDGRID_API_KEY__.

5. Start the services

Start the webhook service:

mesg-core service start webhook

Start discord invitation service:

mesg-core service start discord-invitation

6. Start the application

Start your application like any node application:

node index.js

7. Test the application

Now let's give this super simple application a try.

Trigger the webhook with the following command:

curl -XPOST http://localhost:3000/webhook

🎉 You should have received an email in your inbox with your invitation to our Discord. Come join our community.

Get Help

You need help ? Check out the MESG Forum.

Last Updated: 5/2/2019, 4:03:31 AM