DEV Community 👩‍💻👨‍💻

Cover image for "Grab these vehicles": Send Real Simeon Texts Using Twilio Functions

Posted on

"Grab these vehicles": Send Real Simeon Texts Using Twilio Functions

I started playing Grand Theft Auto Online again after putting it down for several years and I was quickly reminded of one of the most annoying features of the game: Simeon vehicles.

Also known as Simeon Car Export Requests, fans of the game are all too familiar with this mechanic, which has achieved meme-status due to its annoyance and inconvenience.

I was inspired to build this functionality IRL to troll my GTA Online friends with real text messages. This post will quickly walk through how to build your own Simeon texting service in less than 10 minutes using Twilio Functions.

Getting Started

If you've never used Twilio before and you're interested in getting started, consider using my referral code for $10 of free Twilio credit (which goes a really long way and will cover anything needed for this post).

Twilio Functions allow you to quickly and easily execute JavaScript in a serverless environment in response to incoming messages or voice calls (or HTTP requests). Functions are super extensible and can be integrated into other Twilio offerings as well, but I find them best used for quick and silly projects like this one that don't warrant an entire back-end and deployment pipeline.

The first step is to buy a Twilio phone number, which is needed to send outgoing SMS messages. This can be done from the Twilio Console. More info on buying a Twilio number can be found here.

Configuring the Twilio Function

Next, navigate to the Functions section of the Console and create a new function. Give the function a descriptive name and path (I've obscured mine for privacy's sake). For simplicity' sake, make sure that 'Check for valid Twilio signature' is off, since requests to this Function will come from HTTP and not other Twilio services. More information about this can be found in Twilio's Security documentation. The configuration should look similar to this:

Function Configuration

The next step is to paste in the following code into the Function:

exports.handler = function(context, event, callback) {
    messageOptions = [
        'Cheval Surge, Ocelot Jackal , Obey Tailgater, Dundreary Landtstalker, Maibatsu Penumbra.',
        'Dundreary Landstalker, Maibatsu Penumbra, Ocelot F620, Fathom FQ 2, Mammoth Patriot.',
        'Dundreary Landstalker, Maibatsu Penumbra, Ocelot F620, Fathom FQ 2, Bollokan Prairie.',
        'Karin BeeJay XL, Bravado Gresley, Albany Buccaneer, Western Daemon, Western Bagger.',
        'Ubermacht Sentinel XS, Vapid Dominator, Benefactor Schafter, Cheval Surge, Ocelot Jackal.',
        'Benefactor Serrano, Mammoth Patriot, Emperor Habanero, Schyster Fusilade, Bravado Gresley.',
        'Fathom FQ 2, Mammoth Patriot, Emperor Habanero, Schyster Fusilade, Bravado Gresley.'
    randomOption = messageOptions[Math.floor(Math.random() * messageOptions.length)]
    messageBody = "Grab these vehicles: " + randomOption
        to: event.toNumber,
        from: context.SIMEON_NUMBER,
        body: messageBody
    }).then(msg => {
        callback(null, msg.sid);
    }).catch(err => callback(err));
Enter fullscreen mode Exit fullscreen mode

Remember to save the Function after pasting.

The code above will choose a random text message body based on the possible texts that Simeon sends in-game and then send an outgoing SMS via the built-in twilio-node helper library.

Two of the more notable lines are event.toNumber and context.SIMEON_NUMBER.

  • event.toNumber is looking for a query param called toNumber which must be included on incoming requests (an example is shown in the next section).
  • context.SIMEON_NUMBER is looking for an environment variable named SIMEON_NUMBER configured within the Function console.

Set the Environment Variable

The final step is to set this SIMEON_NUMBER environment variable for the so that the Function can access your Twilio phone number it without having to hard-code it. Navigate to the Function Configuration page and add a new environment variable named SIMEON_NUMBER and set the value to the number that was purchased earlier (make sure to enter it in E.164 format).

Function Configuration

Testing the Twilio Function

The way to trigger this Function is via an HTTP request. cURL can be used to trigger the Function from the command line as seen here:

curl -X POST
Enter fullscreen mode Exit fullscreen mode

Replace the URL with the one from your own Function and set the toNumber param to the phone number you want to message.

SMS Screnshot

Wrapping Up

That's all there is to it. The Function can be triggered from any manner such as the command line, a Node back-end, scheduled on a cronjob, etc. The possibilities with Twilio Functions and how to trigger them are endless.

I hope you enjoyed following along with this silly attempt at video game humor. If you have similar ideas for Functions based projects post them in the comments section!

Thanks for reading!

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.