Exemple #1
0
        public async Task <IActionResult> Post(HttpRequestMessage request)
        {
            var events = await request.GetWebhookEventsAsync(configuration["Line:ChannelSecret"]);

            var connectionString = configuration["StorageConnectionString"];
            var talkLog          = await TableStorage <TalkLog> .CreateAsync(connectionString, "ChildsNotification");

            var app = new LineBotApp(line, talkLog);
            await app.RunAsync(events);

            return(new OkResult());
        }
        public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
        {
            var events = await request.GetWebhookEventsAsync(channelSecret);
            var connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
            var blobStorage = await BlobStorage.CreateAsync(connectionString, "linebotcontainer");
            var eventSourceState = await TableStorage<EventSourceState>.CreateAsync(connectionString, "eventsourcestate");

            var app = new LineBotApp(lineMessagingClient, eventSourceState, blobStorage);
            await app.RunAsync(events);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public async Task <IActionResult> Post([FromBody] JToken req)
        {
            var events           = WebhookEventParser.Parse(req.ToString());
            var connectionString = appsettings.LineSettings.StorageConnectionString;
            var blobStorage      = await BlobStorage.CreateAsync(connectionString, "linebotcontainer");

            var eventSourceState = await TableStorage <EventSourceState> .CreateAsync(connectionString, "eventsourcestate");

            var app = new LineBotApp(lineMessagingClient, eventSourceState, blobStorage);
            await app.RunAsync(events);

            return(new OkResult());
        }
Exemple #4
0
        /// <summary>
        /// Main run method
        /// </summary>
        /// <param name="req">HttpRequestMessage</param>
        /// <param name="log">TraceWriter</param>
        /// <returns>Result</returns>
        public static async Task <IActionResult> Run(HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");
                var channelSecret = Environment.GetEnvironmentVariable("ChannelSecret");
                var events        = await req.GetWebhookEventsAsync(channelSecret);

                var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
                var eventSourceState = await TableStorage <EventSourceState> .CreateAsync(connectionString, "eventsourcestate");

                var blobStorage = await BlobStorage.CreateAsync(connectionString, "linebotcontainer");

                // Create the LineBotApp and run it.
                var app = new LineBotApp(lineMessagingClient, eventSourceState, blobStorage, log);
                await app.RunAsync(events);
            }
            catch (InvalidSignatureException e)
            {
                return(new ObjectResult(e.Message)
                {
                    StatusCode = (int)HttpStatusCode.Forbidden
                });
            }
            catch (LineResponseException e)
            {
                log.Error(e.ToString());
                var debugUserId = Environment.GetEnvironmentVariable("DebugUser");
                if (debugUserId != null)
                {
                    await lineMessagingClient.PushMessageAsync(debugUserId, $"{e.StatusCode}({(int)e.StatusCode}), {e.ResponseMessage.ToString()}");
                }
            }
            catch (Exception e)
            {
                log.Error(e.ToString());
                var debugUserId = Environment.GetEnvironmentVariable("DebugUser");
                if (debugUserId != null)
                {
                    await lineMessagingClient.PushMessageAsync(debugUserId, e.Message);
                }
            }

            return(new OkObjectResult("OK"));
        }