forked from microsoft/BotBuilder-Samples
-
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.
Adding Skype sample from documentation
- Loading branch information
Showing
20 changed files
with
1,612 additions
and
0 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,56 @@ | ||
namespace EmergencyServicesBot | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Connector; | ||
|
||
public class AgentListener | ||
{ | ||
// This will send an adhoc message to the user | ||
public static async Task Resume( | ||
string toId, | ||
string toName, | ||
string fromId, | ||
string fromName, | ||
string conversationId, | ||
string message, | ||
string serviceUrl = "https://smba.trafficmanager.net/apis/", | ||
string channelId = "skype") | ||
{ | ||
if (!MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl)) | ||
{ | ||
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl); | ||
} | ||
|
||
try | ||
{ | ||
var userAccount = new ChannelAccount(toId, toName); | ||
var botAccount = new ChannelAccount(fromId, fromName); | ||
var connector = new ConnectorClient(new Uri(serviceUrl)); | ||
|
||
IMessageActivity activity = Activity.CreateMessageActivity(); | ||
|
||
if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId)) | ||
{ | ||
activity.ChannelId = channelId; | ||
} | ||
else | ||
{ | ||
conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id; | ||
} | ||
|
||
activity.From = botAccount; | ||
activity.Recipient = userAccount; | ||
activity.Conversation = new ConversationAccount(id: conversationId); | ||
activity.Text = message; | ||
activity.Locale = "en-Us"; | ||
await connector.Conversations.SendToConversationAsync((Activity)activity); | ||
} | ||
catch (Exception exp) | ||
{ | ||
Debug.WriteLine(exp); | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
namespace EmergencyServicesBot | ||
{ | ||
using System.Web.Http; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
public static class WebApiConfig | ||
{ | ||
public static void Register(HttpConfiguration config) | ||
{ | ||
// Json settings | ||
config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; | ||
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | ||
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented; | ||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings() | ||
{ | ||
ContractResolver = new CamelCasePropertyNamesContractResolver(), | ||
Formatting = Newtonsoft.Json.Formatting.Indented, | ||
NullValueHandling = NullValueHandling.Ignore, | ||
}; | ||
|
||
// Web API configuration and services | ||
|
||
// Web API routes | ||
config.MapHttpAttributeRoutes(); | ||
|
||
config.Routes.MapHttpRoute( | ||
name: "DefaultApi", | ||
routeTemplate: "api/{controller}/{id}", | ||
defaults: new { id = RouteParameter.Optional }); | ||
} | ||
} | ||
} |
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,30 @@ | ||
namespace EmergencyServicesBot | ||
{ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using Microsoft.Bot.Builder.Calling; | ||
using Microsoft.Bot.Connector; | ||
|
||
[BotAuthentication] | ||
[RoutePrefix("api/calling")] | ||
public class CallingController : ApiController | ||
{ | ||
public CallingController() : base() | ||
{ | ||
CallingConversation.RegisterCallingBot(callingBotService => new IVRBot(callingBotService)); | ||
} | ||
|
||
[Route("callback")] | ||
public async Task<HttpResponseMessage> ProcessCallingEventAsync() | ||
{ | ||
return await CallingConversation.SendAsync(this.Request, CallRequestType.CallingEvent); | ||
} | ||
|
||
[Route("call")] | ||
public async Task<HttpResponseMessage> ProcessIncomingCallAsync() | ||
{ | ||
return await CallingConversation.SendAsync(this.Request, CallRequestType.IncomingCall); | ||
} | ||
} | ||
} |
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,68 @@ | ||
namespace EmergencyServicesBot | ||
{ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using Microsoft.Bot.Connector; | ||
|
||
[BotAuthentication] | ||
public class MessagesController : ApiController | ||
{ | ||
/// <summary> | ||
/// POST: api/Messages | ||
/// Receive a message from a user and reply to it | ||
/// </summary> | ||
public async Task<HttpResponseMessage> Post([FromBody]Activity activity) | ||
{ | ||
if (activity.Type == ActivityTypes.Message) | ||
{ | ||
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); | ||
|
||
// calculate something for us to return | ||
int length = (activity.Text ?? string.Empty).Length; | ||
|
||
// return our reply to the user | ||
Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters"); | ||
await connector.Conversations.ReplyToActivityAsync(reply); | ||
} | ||
else | ||
{ | ||
this.HandleSystemMessage(activity); | ||
} | ||
|
||
var response = Request.CreateResponse(HttpStatusCode.OK); | ||
return response; | ||
} | ||
|
||
private Activity HandleSystemMessage(Activity message) | ||
{ | ||
if (message.Type == ActivityTypes.DeleteUserData) | ||
{ | ||
// Implement user deletion here | ||
// If we handle user deletion, return a real message | ||
} | ||
else if (message.Type == ActivityTypes.ConversationUpdate) | ||
{ | ||
// Handle conversation state changes, like members being added and removed | ||
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info | ||
// Not available in all channels | ||
} | ||
else if (message.Type == ActivityTypes.ContactRelationUpdate) | ||
{ | ||
// Handle add/remove from contact lists | ||
// Activity.From + Activity.Action represent what happened | ||
} | ||
else if (message.Type == ActivityTypes.Typing) | ||
{ | ||
// Handle knowing tha the user is typing | ||
} | ||
else if (message.Type == ActivityTypes.Ping) | ||
{ | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.