Exemple #1
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            var connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            if (activity.Type == ActivityTypes.Message)
            {
                var msg = activity.Text;

                if (Regex.IsMatch(msg, "(?<=have we been to )(?<place>[^?]+)", RegexOptions.IgnoreCase))
                {
                    var place = Regex.Match(msg, @"(?<=have we been to )(?<place>[^?]+)", RegexOptions.IgnoreCase)?.Groups["place"]?.Value ?? "";

                    if (!string.IsNullOrWhiteSpace(place))
                    {
                        var visitedPlaces = await _service.GetAllVisitedLocationsAsync();

                        var visitedPlace = visitedPlaces.FirstOrDefault(r => string.Equals(r.Location, place, StringComparison.OrdinalIgnoreCase));

                        if (visitedPlace != null)
                        {
                            await ReplyWithVisitedPlaceAsync(visitedPlace, activity, connector);
                        }
                        else
                        {
                            await ReplyWithUnchosenPlaceAsync(place, activity, connector);
                        }
                    }
                    else
                    {
                        await ReplyWithUnrecognizablePlaceAsync(activity, connector);
                    }
                }
                else if (Regex.IsMatch(msg, "where we should go|recommendation|pick for me", RegexOptions.IgnoreCase))
                {
                    await ReplyWithRandomLocationRecommendation(activity, connector);
                }
                // If the user mentions anything related to the list, give it to them
                else if (Regex.IsMatch(msg, "show|all|list all", RegexOptions.IgnoreCase))
                {
                    await ReplyWithPlaceListAsync(activity, connector);
                }
                else if (Regex.IsMatch(msg, "who's next|who is next|whose (pick|turn) is it", RegexOptions.IgnoreCase))
                {
                    await ReplyWithNextMemberToChoose(activity, connector);
                }
                else
                {
                    await ReplyWithDefaultMessageAsync(activity, connector);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }