Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save beachside-project/826303daa3d865042fc16aafc2e4d8f3 to your computer and use it in GitHub Desktop.
Save beachside-project/826303daa3d865042fc16aafc2e4d8f3 to your computer and use it in GitHub Desktop.
MessagesController_simpleEcho
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
using DialogDemo.Dialogs;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace DialogDemo.Controllers
{
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
[ResponseType(typeof(void))]
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity != null)
{
// one of these will have an interface and process it
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
await DoSomethingAsync(activity);
break;
case ActivityTypes.ConversationUpdate:
case ActivityTypes.ContactRelationUpdate:
case ActivityTypes.Typing:
case ActivityTypes.DeleteUserData:
default:
Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}");
break;
}
}
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
internal async Task DoSomethingAsync(Activity activity)
{
await Conversation.SendAsync(activity, () => new SimpleEchoDIalog());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment