Created
March 23, 2020 03:59
-
-
Save nuwanbando/0c7da52c5ff05c4c2ffa946713edeb01 to your computer and use it in GitHub Desktop.
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
import ballerina/io; | |
import ballerina/http; | |
//import miyurud/twilio; | |
//import ballerina/config; | |
import ballerina/observe; | |
#Twilio config | |
//twilio:TwilioConfiguration twilioConfig = { | |
// accountSId: "ACc055c08964b76ef55b0a755a3edcd6f3", | |
// authToken: "e5f33508721405842550c906c26febb2" | |
// xAuthyKey: config:getAsString("X_AUTHY_KEY") | |
//}; | |
//twilio:Client twilioClient = new(twilioConfig); | |
#sending a whatsapp message with today's weather info | |
public function main() { | |
json|error weatherData = fetchTodaysWeather(); | |
json[] daily = []; | |
if(weatherData is json){ | |
daily = <json[]> weatherData.DailyForecasts; | |
} | |
string message = "Hello " + "Nuwan" + " good morning!! Today is " | |
+ daily[0].Day.IconPhrase.toString() + " and the night is "+ daily[0].Night.IconPhrase.toString() + ". Today's maximum temprature is " | |
+ daily[0].Temperature.Maximum.Value.toString() + "F and the minimum temprature is " | |
+ daily[0].Temperature.Minimum.Value.toString() + "F. Have a great day!! ~this is ur Ballerina weather bot ;)"; | |
io:println(message); | |
// error? pushToWhatsAppResult = pushToWhatsApp(message); | |
// if (pushToWhatsAppResult is error) { | |
// io:println(pushToWhatsAppResult.reason()); | |
// } | |
} | |
@observe:Observable | |
function fetchTodaysWeather() returns @tainted json|error { | |
http:Client accuWeatherEP = new ("http://dataservice.accuweather.com"); | |
http:Response weatherResp = new; | |
weatherResp = check accuWeatherEP->get("/forecasts/v1/daily/1day/"+ "07042" +"?apikey=8dbh68Zg2J6WxAK37Cy2jVJTSMdnyAmV"); | |
return weatherResp.getJsonPayload(); | |
} | |
//@observe:Observable | |
//function pushToWhatsApp(string message) returns error? { | |
// var whatsAppResponse = twilioClient->sendWhatsAppMessage("whatsapp:" + config:getAsString("TWILIO_SANDBOX_NUMBER"), | |
// "whatsapp:" + config:getAsString("DESTINATION_PHONE_NUMBER"), | |
// message); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment