You’ll know if everything worked when the bot says it’s listening. Since there are no plugins loaded yet, the bot will reply with a default message if you send it a text.

Now you’re ready to start writing your own plugins!

Write your own plugins

First, it’s important to understand how TextEverything works under the hood. To handle the SMS side of things we’re using Twilio. Whenever a text message comes in to the configured Twilio phone number, Twilio makes a POST request to the ngrok URL we created earlier. ngrok forwards the request to a route defined in Express running on our local machine as part of the TextEverything application. This is why it is necessary to expose port 1337 to the public internet – so that Twilio can interact with TextEverything.

When TextEverything receives that POST request, a number of things happen which you can see in the diagram below:

First, TextEverything ensures the request actually came from Twilio, using the X-Twilio-Signature header. If not, the request is silently discarded. Then, all .js files in the plugins directory are enumerated, and the first portion of the text message is matched against the aliases defined in each .js file. If there is a match, the run() method contained within that plugin is executed. Otherwise, TextEverything responds with an “invalid command” message.

TextEverything’s plugin system that sets it apart as an easy way to build a bot to your needs – if you can write it in JavaScript, you can trigger it with TextEverything. Testing a plugin is as simple as placing a .js file in the plugins directory and restarting the server. Your plugin should then respond to its aliases when you text the number you’ve assigned to TextEverything. Let’s make one now to try that out!

TextEverything plugins are structured like so: