"Grab these vehicles": Send Real Simeon Texts Using Twilio Functions
Tags: twilio, sms, gtav
Published: 2020-06-11 04:16:45

---
title: "Grab these vehicles": Send Real Simeon Texts Using Twilio Functions
published: true
description: Send IRL Simeon vehicle requests with Twilio Functions and SMS. Troll wisely!
tags: twilio, sms, gtav
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/6cvqxtfpjahdmpeozqgz.jpg
---

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](https://gta.fandom.com/wiki/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](https://www.twilio.com/docs/runtime/functions).

# Getting Started

If you've never used Twilio before and you're interested in getting started, consider using [my referral code](www.twilio.com/referral/u9A86w) 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](https://www.twilio.com/console/phone-numbers/incoming). More info on buying a Twilio number can be found [here](https://support.twilio.com/hc/en-us/articles/223135247-How-to-Search-for-and-Buy-a-Twilio-Phone-Number-from-Console).

# Configuring the Twilio Function

Next, navigate to the [Functions](https://www.twilio.com/console/functions/manage) 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](https://www.twilio.com/docs/usage/security). The configuration should look similar to this:

![Function Configuration](https://dev-to-uploads.s3.amazonaws.com/i/mpeenmqg2nxq2lctbo8n.png)


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

```javascript 
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
    context.getTwilioClient().messages.create({
        to: event.toNumber,
        from: context.SIMEON_NUMBER,
        body: messageBody
    }).then(msg => {
        callback(null, msg.sid);
    }).catch(err => callback(err));
};
```

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](https://www.twilio.com/console/functions/configure) 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](https://www.twilio.com/docs/glossary/what-e164) format).

![Function Configuration](https://dev-to-uploads.s3.amazonaws.com/i/5vfn7r95q8j1dgj1xxep.png)

# 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:

```bash
curl -X POST https://xxxxxx-yyyy-0000.twil.io/simeon?toNumber=15555555555
```

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](https://dev-to-uploads.s3.amazonaws.com/i/7u65gjew36z3a8hparqs.jpg)

# 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!