Before Starting

GitHub Repository: https://github.com/shreythecray/infiltration

The hackathon ends soon, and we are giving away over $1K in prizes! Join us in building a cool project and winning any of the following prizes. 🏆

Additionally, everyone who submits a project successfully integrating the Courier API will receive a $20 Amazon gift card! Submissions close on September 28th. Register now to submit this project for a chance to win some cool prizes.

Register for the Hackathon: https://courier-hacks.devpost.com/

Not sure where to start? In this tutorial, we will create a Discord bot that sends daily automated messages encrypted in Morse code with Node.js and the Courier API.

What is Going On?

Recap

We are secret agents, and we previously built an application to send secret messages encrypted in Morse code to communicate with our spy network. Learn more >

Last time, headquarters told us that one of our spies had leaked sensitive, top-secret information to our enemies, so we built a lie detector that alerted our spy network when we identified the mole. We used Azure's Cognitive Services to perform facial recognition on everyone on our team and Courier to broadcast the identity of the mole to our spy network. Learn more >

What’s Next:

We have successfully identified the mule and have alerted our spy network! In an unfortunate turn of events, the mule happens to be our partner, Agent X, and now we are being suspected as a traitor as well. Since we are highly skilled, Headquarters knows that the Lie Detector won’t work on us, but we have been placed off-duty until we can prove that we are innocent.

Before we were removed from duty, we were able to use the Lie Detector to find out that the enemy had thousands of civilians under control in a secret Discord server. The civilians are being brainwashed with enemy propaganda every day. To prove our innocence, we decide to go undercover and infiltrate the enemy’s Discord server. With the help of Agent X, we have been added to the server as an administrator. Our plan is to create and install a Discord bot that automates encrypted messages to the civilians and alerts them about the situation so that they can escape.

Let’s Build

Pre-reqs:

Part 1: Set Up Node.js Project

Today, we will be building this with Node.js. If you’re curious about how to build this project using Ruby, cURL, Powershell, Go, PHP, Python, or Java, let us know: https://discord.com/invite/courier. You can also access code for these within our API reference. Let’s get started:

Part 2: Create a Discord Bot

Now, Courier has access to sending messages to this server as the bot.

Part 3: Send Messages

{
    "courier": {},
    "data": {},
    "profile": {
      "discord": {
        "channel_id": "768866348853383208"
      }
    },
    "override": {}
  }

Part 4: Encrypt Message with the Morse API

async function encryptMessage(originalMessage) {
  }

const morseOptions = {
      method: 'GET',
      headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json'
      }
  };

const morseEndpoint = "https://api.funtranslations.com/translate/morse.json?text="+originalMessage

const morseResponse = await fetch(morseEndpoint, morseOptions);
const morseResponseJSON = await morseResponse.json();
const encryptedMessage = morseResponseJSON.contents.translated;
console.log(encryptedMessage);
return encryptedMessage;

NOTE: The Morse API has a rate limit, which may give you an error if you run it too many times within the hour. In this case, you will have to wait for some time before continuing.

Part 5: Automate Messages

Learn about Automations >

Check out the Automations API reference >

async function runDiscordAutomation() {
  }

const originalMessage = "run%20while%20you%20can%20you%20can%20find%20shelter%20here";
  const encryptedMessage = await encryptMessage(originalMessage);

const automationsEndpoint = "https://api.courier.com/automations/invoke"

  const courierOptions = {
      method: "POST",
      headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: 'Bearer ' + process.env.apiKey
      },
      body: JSON.stringify({
          //next steps
      }),
  };

body: JSON.stringify({
      "automation": {
      },
      "data": {
      } 
  }),

"automation": {
      "steps": [],
  },

{
      "action": "send",
      "message": {
          "template": templateID,
          "to": {
              "discord": {
                  "channel_id": process.env.channelID
              }
          }
      }
  },
{
      "action": "send",
      "duration":"1 day"
  },

.

"data": {
      "secretMessage": encryptedMessage
  }

fetch(automationsEndpoint, courierOptions)
      .then((response) => response.json())
      .then((response) => console.log(response))
      .catch((err) => console.error(err));


Conclusion

Our Discord bot is ready to save some civilians. Try building a Discord bot of your own and tweet a screenshot of your Courier automated messages in action, and we will send a gift to the first three Secret Agents to complete this task! Head to courier.com/hack-now to get started. Don’t forget to submit your project to our Hackathon for a chance to win over $1000 in cash and prizes!

Quick Links

🔗 GitHub Repository: https://github.com/shreythecray/infiltration

🔗 Courier: app.courier.com

🔗 Register for the Hackathon: https://courier-hacks.devpost.com/

🔗 Discord Application and Bot Guide: https://discord.com/developers/docs/getting-started

🔗 Courier Discord Provider Docs: https://www.courier.com/docs/guides/providers/direct-message/discord/

🔗 Courier Automations Docs: https://www.courier.com/docs/automations/

🔗 Courier Automations API Reference: https://www.courier.com/docs/reference/

Originally published here.