-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
137 additions
and
59 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Adapters; | ||
using Microsoft.Bot.Connector; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace WeatherBot.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class MessagesController : Controller | ||
{ | ||
public static BotFrameworkAdapter activityAdapter = null; | ||
public static Bot bot = null; | ||
|
||
public MessagesController(IConfiguration configuration) | ||
{ | ||
if (activityAdapter == null) | ||
{ | ||
string appId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value; | ||
string appPassword = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppPasswordKey)?.Value; | ||
|
||
// create the activity adapter to send/receive Activity objects | ||
activityAdapter = new BotFrameworkAdapter(appId, appPassword); | ||
bot = new Bot(activityAdapter) | ||
.OnReceive(async (context) => | ||
{ | ||
// THIS IS YOUR BOT LOGIC | ||
if (context.Request.Type == ActivityTypes.Message) | ||
{ | ||
string city = context.Request.Text; | ||
if (!string.IsNullOrWhiteSpace(city)) | ||
{ | ||
string weatherJson = await Weather.GetWeatherByCityName(city); | ||
context.Reply(weatherJson); | ||
//return new ReceiveResponse(true); | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
else | ||
{ | ||
context.Reply("Type city name to get weather"); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
[Authorize(Roles = "Bot")] | ||
[HttpPost] | ||
public async void Post([FromBody]Activity activity) | ||
{ | ||
await activityAdapter.Receive(HttpContext.Request.Headers, activity); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace WeatherBot | ||
{ | ||
public static class Weather | ||
{ | ||
const string WeatherApiBaseUrl = "http://api.openweathermap.org/data/2.5/weather?{0}&units=imperial&APPID=a0f75f6b2f7ce29295822d2862df66a6"; | ||
static HttpClient client = new HttpClient(); | ||
|
||
public static async Task<string> GetWeatherByCityName(string cityName) | ||
{ | ||
HttpResponseMessage response = await client.GetAsync( | ||
String.Format(WeatherApiBaseUrl, "q=" + cityName)); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
return await response.Content.ReadAsStringAsync(); | ||
} | ||
else | ||
{ | ||
return $"Uh oh, weather for {cityName} is not found"; | ||
} | ||
} | ||
|
||
public static string GetCurrentTemperature(string cityName) | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,9 @@ | |
"Default": "Warning" | ||
} | ||
} | ||
} | ||
}, | ||
|
||
"MicrosoftAppId": "", | ||
"MicrosoftAppPassword": "", | ||
"DataConnectionString": "" | ||
} |