public IActionResult Post([FromBody] CallbackUpdate update)
        {
            if (update.Secret == secret) // VK secret string check
            {
                try                      // If something went wrong return Bad Request
                {
                    switch (update.Type) // Event type
                    {
                    case "confirmation":
                        return(Ok(Environment.GetEnvironmentVariable("VK_CONFIRMATION")));

                    case "message_new":
                        eventsHandler.MessageNewEvent(update.Object);
                        return(Ok("ok"));

                    default:
                        logger.Warn($"Unknown event type '{update.Type}': {update.Object.ToString(Newtonsoft.Json.Formatting.None)} ");
                        return(BadRequest("Unknown event"));
                    }
                }
                catch (Exception exception)
                {
                    string str = "An error occurred while handling request";
                    logger.Error(exception, str);
                    return(BadRequest(str));
                }
            }
            else
            {
                return(Forbid());
            }
        }
Esempio n. 2
0
        public async void StartHandler()
        {
            this.onDataUpdate = (string updateType, System.Dynamic.ExpandoObject obj) =>
            {
                switch (updateType)
                {
                case "ActionUpdate":
                    CallbackUpdate callback      = (dynamic update) => { return; };
                    dynamic        args          = obj;
                    dynamic        updatedAction = args.Action;
                    dynamic        changesList   = args.Changes;


                    if (args.Delete)
                    {
                        callback = DeleteAction;
                    }
                    if (args.UpdateDescription)
                    {
                        callback = UpdateAction;
                    }
                    if (args.CreateAction)
                    {
                        callback = CreateNewAction;
                    }
                    if (args.AddSubAction)
                    {
                        callback = AddSubAction;
                    }

                    callback(args.Changes);
                    DynamicData = obj;

                    break;

                default:
                    return;
                    ////////
                }
            };
        }