コード例 #1
0
        public static AdaptiveCardInvoke ValidateRequest(ITurnContext turnContext)
        {
            var activity = turnContext.Activity;
            AdaptiveCardInvoke request = null;

            if (activity.Value == null)
            {
                AdaptiveCardActionException.BadRequest("Missing value property");
            }

            try
            {
                request = ((JObject)turnContext.Activity.Value).ToObject <AdaptiveCardInvoke>();
            }
            catch (Exception)
            {
                AdaptiveCardActionException.BadRequest("Value property is not properly formed");
            }

            if (request.Action == null)
            {
                AdaptiveCardActionException.BadRequest("Missing action property");
            }

            if (request.Action.Type != AdaptiveCardsConstants.ActionExecute)
            {
                AdaptiveCardActionException.ActionNotSupported(request.Action.Type);
            }

            return(request);
        }
コード例 #2
0
        public static T ValidateAction <T>(AdaptiveCardInvoke request)
        {
            if (request.Action.Data == null)
            {
                AdaptiveCardActionException.BadRequest("Missing data property");
            }

            try
            {
                return(((JObject)request.Action.Data).ToObject <T>());
            }
            catch (Exception)
            {
                AdaptiveCardActionException.BadRequest("Action.Data property is not properly formed");
            }

            return(default(T));
        }