Skip to content

Controllers

sang004 edited this page Jul 22, 2017 · 1 revision

These controllers are called depending on what type of medium was used to communicate with the bot, either in text messaging or calling of Skype.

* CallingController.cs

It starts with [BotAuthentication] which automatically picks up the and from Web.config. From its constructor, it initiates a new simplecallbot object.

        public CallingController() : base()
        {
            CallingConversation.RegisterCallingBot(c => new simplecallbot(c));
        }

So based on the endpoint called by the bot, either [Route("callback")] or [Route("call")].

        // Callback to the user
        [Route("callback")]
        public async Task<HttpResponseMessage> ProcessCallingEventAsync()
        {
            return await CallingConversation.SendAsync(Request, CallRequestType.CallingEvent);
        }

        // Incoming call events
        [Route("call")]
        public async Task<HttpResponseMessage> ProcessIncomingCallAsync()
        {
            return await CallingConversation.SendAsync(Request, CallRequestType.IncomingCall);
        }

* MessagesController.cs

If the user text messages the bot, this controller will be activated. [BotAuthentication] is also present in this script. Below is the first function that starts it all, input being activity which contains message string we need to determine what to do next.

        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {

Firstly we check check the user's response to the HeroCard posted by simplecallbot. In this case, we are checking 2 variables on the botState.

  1. activeMode - retreived from HeroCard, either call / record
  2. activeAcc - retrieved from subsequent message, 'as '

The Herocard sends back the user's response in user activity as well, similar to how we will be able to see the activeAcc's normal text message response. When response is received, we use functions in BotStateEdit to edit the BotState.

            //get current botstate userdata and see if the settings required configuration, else give generic response
            string currMode = BotStateEdit.getUserData(activity, "activeMode", ref retries);
            string currAcc = BotStateEdit.getUserData(activity, "activeAcc", ref retries);

            if (currMode == null || currAcc == null)
            {
                if (activity.Text.ToLower().Contains("call") || activity.Text.ToLower().Contains("record"))
                {
                    BotStateEdit.setUserData(activity, "activeMode", activity.Text.ToLower(), ref retries);
                }
                else if (activity.Text.ToLower().Contains("as"))
                {
                    string acc = (activity.Text.ToLower()).Split(' ')[1];
                    BotStateEdit.setUserData(activity, "activeAcc", acc, ref retries);
                }
            }

Clone this wiki locally