{"info":{"_postman_id":"662d1d34-37fe-46e5-827c-f594aa217872","name":"Slack Weather Bot","description":"<html><head></head><body><p>This collection acts as a weather bot for you which posts the current weather to a specified Slack channel.</p>\n<h3 id=\"setup\">Setup:</h3>\n<p>For the setup, you will need three things.</p>\n<ol>\n<li><strong>Google Maps API Key</strong>: You can generate an API Key using this <a href=\"https://developers.google.com/maps/documentation/geocoding/get-api-key\">link</a></li>\n<li><strong>DarkSky API Key</strong>: The DarkSky API returns weather conditions based on a particular latitude and longitude. You would be needing an API Key to use it. Head to <a href=\"https://darksky.net/dev\">DarkSky Dev</a> and register for a free account and generate an API Key.</li>\n<li><strong>Slack Webhook URL</strong>: Slack allows you to generate incoming webhooks for your team using which you can send a message to a specific channel or user. Go to <a href=\"https://api.slack.com/incoming-webhooks\">Slack</a> to learn more about how you can generate one.</li>\n</ol>\n<p>Once you have all these three, you can add them to the attached environment and your collection is ready for use.</p>\n<p>A sample weather report on Slack would look something like this.</p>\n<p><img src=\"https://user-images.githubusercontent.com/6972850/47005820-361a0b00-d152-11e8-8386-fa82df283821.png\" alt=\"Example\"></p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"owner":"4630964","collectionId":"662d1d34-37fe-46e5-827c-f594aa217872","publishedId":"S1Lr3qjv","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"publishDate":"2019-04-30T07:16:05.000Z"},"item":[{"name":"Get Latitude and Longitude","event":[{"listen":"prerequest","script":{"id":"1d5df0ee-b0a6-45ac-ae8f-f518e31b60cc","exec":[""],"type":"text/javascript"}},{"listen":"test","script":{"id":"862e14a5-3e46-4117-90e7-61780e0e2836","exec":["pm.test(\"Status code is 200\", function() {","    pm.response.to.have.status(200);","});","","if (pm.response.code === 200) {","    let locationData = pm.response.json(),","        latLong = _.get(locationData, 'results.0.geometry.location.lat') + \",\" + _.get(locationData, 'results.0.geometry.location.lng'),","        formattedAddress = _.get(locationData, 'results.0.formatted_address');","","    pm.environment.set(\"formattedAddress\", formattedAddress);","    pm.environment.set(\"latLong\", latLong);","}"],"type":"text/javascript"}}],"id":"b0c0868b-cba2-4127-afc8-a1abf4e03cb1","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"https://maps.googleapis.com/maps/api/geocode/json?address={{location}}&key={{GeocodingAPIKey}}","description":"<p>This request calls the Google Maps API to fetch the coordinates (latitude and longitude) of the specified place.</p>\n","urlObject":{"protocol":"https","path":["maps","api","geocode","json"],"host":["maps","googleapis","com"],"query":[{"description":{"content":"<p>The name of the location for which you want the weather for</p>\n","type":"text/plain"},"key":"address","value":"{{location}}"},{"key":"key","value":"{{GeocodingAPIKey}}"}],"variable":[]}},"response":[],"_postman_id":"b0c0868b-cba2-4127-afc8-a1abf4e03cb1"},{"name":"Get Weather","event":[{"listen":"prerequest","script":{"id":"f27f9925-077d-4a5d-82a0-36896d012f37","exec":[""],"type":"text/javascript"}},{"listen":"test","script":{"id":"8c8aa511-4766-45ad-8280-dde7e71b649b","exec":["pm.test(\"Status code is 200\", function() {","    pm.response.to.have.status(200);","});","","if (pm.response.code === 200) {","    let jsonResult = pm.response.json();","","    pm.environment.set(\"icon\", _.get(jsonResult, 'currently.icon'));","    pm.environment.set(\"temp\", _.get(jsonResult, 'currently.temperature'));","    pm.environment.set(\"summary\", _.get(jsonResult, 'currently.summary'));","}"],"type":"text/javascript"}}],"id":"6bd4c71d-98f7-47c4-ae5f-7512d56ac7f9","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"https://api.darksky.net/forecast/{{ForecastAPIKey}}/{{latLong}}","urlObject":{"protocol":"https","path":["forecast","{{ForecastAPIKey}}","{{latLong}}"],"host":["api","darksky","net"],"query":[],"variable":[]}},"response":[],"_postman_id":"6bd4c71d-98f7-47c4-ae5f-7512d56ac7f9"},{"name":"Send weather to Slack","event":[{"listen":"prerequest","script":{"id":"44ce2f66-e659-476e-9744-76ed67a30433","exec":["let temp = Math.round(parseInt(pm.environment.get(\"temp\"))),","    title = \"Weather for \" + pm.environment.get(\"formattedAddress\"),","    body = \"The temperature is \" + globals.temp + \" °C.\",","    imageUrl;","    ","pm.environment.set(\"temp\", temp);","","if (globals.icon === \"clear-day\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/01-s.png\";","else if (globals.icon === \"clear-night\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/33-s.png\";","else if (globals.icon === \"rain\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/18-s.png\";","else if (globals.icon === \"fog\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/11-s.png\";","else if (globals.icon === \"snow\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/22-s.png\";","else if (globals.icon === \"wind\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/32-s.png\";","else if (globals.icon === \"cloudy\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/07-s.png\";","else if (globals.icon === \"sleet\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/25-s.png\";","else if (globals.icon === \"partly-cloudy-day\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/03-s.png\";","else if (globals.icon === \"partly-cloudy-night\")","    imageUrl = \"https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/35-s.png\";","","pm.environment.set(\"title\", title);","pm.environment.set(\"body\", body);","pm.environment.set(\"imageUrl\", imageUrl);"],"type":"text/javascript"}},{"listen":"test","script":{"id":"01c6a889-8f06-4920-b20f-90574a9e2dbe","exec":["pm.test(\"Status code is 200\", function () {","    pm.response.to.have.status(200);","});"],"type":"text/javascript"}}],"id":"222f141a-7672-46e5-b4c0-9b38e3ce1866","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"username\": \"weatherbot\",\n  \"icon_emoji\": \":earth_africa:\",\n  \"attachments\": [\n        {\n            \"fallback\": \"{{title}}\",\n            \"title\": \"{{title}}\",\n            \"text\": \"{{body}}\",\n            \"thumb_url\": \"{{imageUrl}}\",\n            \"color\": \"#7CD197\"\n        }\n    ]\n}"},"url":"{{slackWebhookUrl}}","urlObject":{"host":["{{slackWebhookUrl}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"222f141a-7672-46e5-b4c0-9b38e3ce1866"}],"event":[{"listen":"prerequest","script":{"id":"7c57a12f-67cc-49f2-bb61-d47760a86589","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"89ab410f-29f7-4a4c-aefb-c7831359cc3c","type":"text/javascript","exec":[""]}}]}