Skip to content

Instantly share code, notes, and snippets.

View dbabbs's full-sized avatar
Focusing

Dylan Babbs dbabbs

Focusing
View GitHub Profile

Step 1 - Installing the XYZ CLI

In this tutorial, we'll cover what you need to do to install and use the XYZ Command Line Interface (CLI).

Download Node.js and install npm

Duration: 10:00

The XYZ CLI requires Node Package Manager or npm, which is included with Node.js.

To check if you have Node.js installed, run this command in your terminal:

var geocodingParamOne = {
searchText: '200 S Mathilda Ave, Sunnyvale, CA'
};
var geocodingParamTwo = {
searchText: '700 S Mathilda Ave, Sunnyvale, CA'
};
var geocoder = platform.getGeocodingService();
{
"name": "here-twilio",
"version": "1.0.0",
"description": "Example project for blog demo featuring HERE Location Services and Twilio Programmable SMS",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dylan Babbs <dylan.babbs@here.com> (http://developer.here.com)",
"license": "ISC",
//Node modules & setup
const http = require('http');
const express = require('express');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const bodyParser = require('body-parser');
const request = require('request');
//HERE credentials
const hereID = 'YOUR-HERE-ID';
const hereCode = 'YOUR-HERE-CODE';
if (geocodeJson.Response.View[0] == null) {
//Can't find placeResults
twiml.message('No search results found for "' + searchQuery + '" in the area. Please try again.');
res.writeHead(200, {
'Content-Type': 'text/xml'
});
res.end(twiml.toString());
return;
}
if (!incoming.includes('near')) { //Making sure it is in correct format
twiml.message('Please send a message with a place name and address. Example: "Mexican food near 701 Pike Street Seattle"');
res.writeHead(200, {
'Content-Type': 'text/xml'
});
res.end(twiml.toString());
return;
}
twiml.message(places[parseInt(incoming) - 1].name + ' is located at ' + places[parseInt(incoming) - 1].address);
res.writeHead(200, {
'Content-Type': 'text/xml'
});
res.end(twiml.toString());
places = []; //Empty places to restart
app.post('/sms', (req, res) => {
const twiml = new MessagingResponse();
var incoming = req.body.Body;
if (incoming.length > 1) {
request.get(geocodeURL, (error, response, body) => {
//geocode request
request.get(placesURL, (error, response, body) => {
//Places request
twiml.message(responseMessage + '\nReply with # to learn more information');
res.writeHead(200, {
'Content-Type': 'text/xml'
});
res.end(twiml.toString());
var responseMessage = 'Here are the ' + resultAmount + ' closest ' + searchQuery +
' places to you: \n';
for (i = 0; i < resultAmount; i++) {
if (placeResults[i].resultType != 'category') {
places.push({
name: placeResults[i].title,
category: placeResults[i].category,
address: placeResults[i].vicinity
});