Learn how to quickly modify your existing Twilio API calls to send SMS messages using the SMS Gateway Emulator app. With minimal code changes, you can switch from Twilio services to our app, saving costs and gaining full control over your SMS gateway.
There are 2 ways to emulate Twilio API:
Change the API URL directly.
Via our Proxy Server.
Whatever method you choose, ensure that you update the following variables to integrate with SMS Gateway Emulator:
TWILIO_ACCOUNT_SID
→ EMULATOR_TWILIO_ACCOUNT_SID
TWILIO_AUTH_TOKEN
→ EMULATOR_TWILIO_AUTH_TOKEN
TWILIO_CALLER_ID
→ EMULATOR_SENDER_ID
For reference, check the official Twilio documentation:
https://www.twilio.com/docs/libraries
https://www.twilio.com/docs/usage/api#send-an-sms-with-twilios-api
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "Body=This is the ship that made the Kessel Run in fourteen parsecs?" \
--data-urlencode "From=$TWILIO_CALLER_ID" \
--data-urlencode "To=+15558675310" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
curl -X POST "https://api.smsgatewayemulator.com/2010-04-01/Accounts/$EMULATOR_TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "Body=This is the ship that made the Kessel Run in fourteen parsecs?" \
--data-urlencode "From=$EMULATOR_SENDER_ID" \
--data-urlencode "To=+15558675310" \
-u $EMULATOR_TWILIO_ACCOUNT_SID:$EMULATOR_TWILIO_AUTH_TOKEN
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$EMULATOR_TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "Body=This is the ship that made the Kessel Run in fourteen parsecs?" \
--data-urlencode "From=$EMULATOR_SENDER_ID" \
--data-urlencode "To=+15558675310" \
-u $EMULATOR_TWILIO_ACCOUNT_SID:$EMULATOR_TWILIO_AUTH_TOKEN \
--cacert ./sms_gateway_emulator_ca.crt \
--proxy https://proxy.smsgatewayemulator.com \
--proxy-cert ./sms_gateway_emulator_ca.crt
import os
from twilio.rest import Client
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)
message = client.messages.create(from_=os.environ["TWILIO_CALLER_ID"], body='Hello from SMS-Gateway-Emulator', to='+15558675310' )
print(message.body)
import os
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient
# set CA certificate for HTTPS requests. This is necessary because we are using a self-signed certificate
os.environ['REQUESTS_CA_BUNDLE'] = os.path.abspath('./sms_gateway_emulator_ca.crt')
proxy_client = TwilioHttpClient(proxy={'https': 'https://proxy.smsgatewayemulator.com'})
account_sid = os.environ["EMULATOR_TWILIO_ACCOUNT_SID"]
auth_token = os.environ["EMULATOR_TWILIO_AUTH_TOKEN"]
# Set up proxy to our SMS-Gateway-Emulator server.
client = Client(account_sid, auth_token, http_client=proxy_client)
message = client.messages.create(from_=os.environ["EMULATOR_SENDER_ID"], body='Hello from SMS-Gateway-Emulator', to='+15558675310' )
print(message.body)
const twilio = require("twilio");
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function createMessage() {
const message = await client.messages.create({
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
from: process.env.TWILIO_CALLER_ID,
to: "+15558675310",
});
console.log(message.body);
}
createMessage();
const twilio = require('twilio');
const axios = require('axios');
const accountSid = process.env.EMULATOR_TWILIO_ACCOUNT_SID;
const authToken = process.env.EMULATOR_TWILIO_AUTH_TOKEN;
// Use a custom request client to change the API url
const axiosInstance = axios.create();
const customRequestClient = {
request: async (options) => {
try {
const auth = Buffer.from(`${accountSid}:${authToken}`).toString('base64');
const response = await axiosInstance({
method: options.method || 'POST',
url: (options.uri || options.url).replace('api.twilio.com', 'api.smsgatewayemulator.com'),
data: options.data,
headers: {...options.headers, 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': `Basic ${auth}`},
params: options.params
});
return {statusCode: response.status, body: response.data};
} catch (error) {
if (error.response) {
return {statusCode: error.response.status, body: error.response.data};
}
throw error;
}
}
};
const client = twilio(accountSid, authToken, {httpClient: customRequestClient});
async function createMessage() {
const message = await client.messages.create({
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
from: process.env.EMULATOR_SENDER_ID,
to: "N:Node.js Demo",
});
console.log(message);
}
createMessage();
Give the phone number N:notification title to send a notification to your phone, instead of sending a SMS message.