Skip to content

Instantly share code, notes, and snippets.

@sslotsky
Created August 30, 2018 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sslotsky/4a549da13888d11773e9f50b3b1020b7 to your computer and use it in GitHub Desktop.
Save sslotsky/4a549da13888d11773e9f50b3b1020b7 to your computer and use it in GitHub Desktop.
function apiUrl(endpoint) {
const url = new URL(`https://platform.tillmobile.com/api/${endpoint}`);
url.searchParams.set("username", process.env.REACT_APP_TILL_USERNAME);
url.searchParams.set("api_key", process.env.REACT_APP_TILL_API_KEY);
return url;
}
function postData(url, data) {
return fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8"
},
body: JSON.stringify(data)
});
}
export async function sendMessage(phoneNumbers, message) {
const res = await postData(apiUrl("send"), {
phone: phoneNumbers,
text: message
});
return res.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment