public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
            [Table("LineAccount")] CloudTable accountTable,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            IEnumerable <WebhookEvent> events;

            try
            {
                string channelSecret = Environment.GetEnvironmentVariable("LINE_COMICS_CHANNEL_SECRET");
                events = await req.GetWebhookEventsAsync(channelSecret);
            }
            catch (InvalidSignatureException e)
            {
                return(req.CreateResponse(HttpStatusCode.Forbidden, new { Message = e.Message }));
            }

            try
            {
                string          channelId = Environment.GetEnvironmentVariable("LINE_COMICS_CHANNEL_ID");
                Line.LineBotApp bot       = new Line.LineBotApp(channelId, messagingClient, accountTable, log);
                await bot.RunAsync(events);
            }
            catch (Exception e)
            {
                log.LogError(e.Message);
            }

            return(req.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 2
0
 private static async Task SendLineMessageAsync(CloudTable accountTable, IList <ItemLookUpResult.Item> itemList, ILogger log)
 {
     string channelId = Environment.GetEnvironmentVariable("LINE_COMICS_CHANNEL_ID");
     var    lineBot   = new Line.LineBotApp(channelId, lineMessagingClient, accountTable, log);
     await lineBot.MulticastItemMessagesAsync(itemList);
 }