Created
July 1, 2016 09:00
-
-
Save beachside-project/3b909e03af248ca2375108a321599c6e to your computer and use it in GitHub Desktop.
MessagesController1
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
using System.Threading.Tasks; | |
using System.Web.Http; | |
using FormFlow1.Dialogs; | |
using Microsoft.Bot.Builder.Dialogs; | |
using Microsoft.Bot.Builder.FormFlow; | |
using Microsoft.Bot.Connector; | |
namespace FormFlow1.Controllers | |
{ | |
[BotAuthentication] | |
public class MessagesController : ApiController | |
{ | |
/// <summary> | |
/// POST: api/Messages | |
/// Receive a message from a user and reply to it | |
/// </summary> | |
public async Task<Message> Post([FromBody]Message message) | |
{ | |
if (message.Type == "Message") | |
{ | |
return await Conversation.SendAsync(message, MakeRootDialog); | |
} | |
else | |
{ | |
return HandleSystemMessage(message); | |
} | |
} | |
internal static IDialog<SandwichOrder> MakeRootDialog() | |
=> Chain.From(() => FormDialog.FromForm(SandwichOrder.BuildForm)); | |
private Message HandleSystemMessage(Message message) | |
{ | |
if (message.Type == "Ping") | |
{ | |
Message reply = message.CreateReplyMessage(); | |
reply.Type = "Ping"; | |
return reply; | |
} | |
else if (message.Type == "DeleteUserData") | |
{ | |
// Implement user deletion here | |
// If we handle user deletion, return a real message | |
} | |
else if (message.Type == "BotAddedToConversation") | |
{ | |
} | |
else if (message.Type == "BotRemovedFromConversation") | |
{ | |
} | |
else if (message.Type == "UserAddedToConversation") | |
{ | |
} | |
else if (message.Type == "UserRemovedFromConversation") | |
{ | |
} | |
else if (message.Type == "EndOfConversation") | |
{ | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment