Skip to content

Instantly share code, notes, and snippets.

@Kento-E
Last active December 11, 2018 03:26
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 Kento-E/bef453d12162fae44af4e023622e324a to your computer and use it in GitHub Desktop.
Save Kento-E/bef453d12162fae44af4e023622e324a to your computer and use it in GitHub Desktop.
Hangouts Chatbot: getting lat, lng & address.
{
"timeZone": "Asia/Tokyo",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"chat": {
}
}
function onAddToSpace(event) {
if (event.space.type == "DM") {
var name = event.user.displayName;
return {
text: "@" + name +
" さん、追加ありがとうございます。場所の名前を入力してみてください。"
};
} else {
return {
text: event.space.displayName + "への追加ありがとうございます。場所の名前を入力してみてください。"
}
}
}
function onMessage(event) {
// Creates a new Geocoder object.
var geocoder = Maps.newGeocoder();
// Creates a Geocoder with the language set to Japanese.
geocoder = geocoder.setLanguage('ja');
// Creates a Geocoder with the region set to Japan.
// geocoder = Maps.newGeocoder().setRegion('ja');
var msg = event.message.argumentText;
// Delete Spaces
msg = msg.replace(/ /g, '');
var response = geocoder.geocode(msg);
for (var i = 0; i < response.results.length; i++) {
var result = response.results[i];
}
if (result){
return {
text: "住所: " + result.formatted_address
+ "\n" + "緯度: " + result.geometry.location.lat
+ "\n" + "経度: " + result.geometry.location.lng
+ "\n" + "URL: https://www.google.co.jp/maps/search/" + msg + "/"
};
// 絵文字が含まれる場合はそのまま返す
} else if(msg.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)) {
return {
text: msg
}
} else {
return {
text: "結果が出力できませんでした。 \n 入力内容をお確かめの上、再度入力してください。"
};
}
}
function onRemoveFromSpace(event) {
return {
text: "退出します。"
};
}
function onCardClick(event) {
return {
text: "カードがクリックされました。"
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment