Last active
December 11, 2018 03:26
-
-
Save Kento-E/bef453d12162fae44af4e023622e324a to your computer and use it in GitHub Desktop.
Hangouts Chatbot: getting lat, lng & address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"timeZone": "Asia/Tokyo", | |
"dependencies": { | |
}, | |
"exceptionLogging": "STACKDRIVER", | |
"chat": { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "カードがクリックされました。" | |
}; | |
} |
Author
Kento-E
commented
Oct 30, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment