Exemplo n.º 1
0
 public TalkManager(BingoBotTableStorage tableStorage, BingoBotBlobStorage blobStrorage, LineMessagingClient messagingClient, TraceWriter log)
 {
     _tableStorage    = tableStorage;
     _blobStorage     = blobStrorage;
     _messagingClient = messagingClient;
     _log             = log;
 }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                var channelSecret    = ConfigurationManager.AppSettings["ChannelSecret"];
                var connectionString = ConfigurationManager.AppSettings["AzureWebJobsStorage"];

                var events = await req.GetWebhookEventsAsync(channelSecret);

                var talkManager = new TalkManager(
                    await BingoBotTableStorage.CreateAsync(connectionString),
                    await BingoBotBlobStorage.CreateAsync(connectionString),
                    LineMessagingClient,
                    log);

                await talkManager.RunAsync(events);

                return(req.CreateResponse(HttpStatusCode.OK));
            }
            catch (InvalidSignatureException e)
            {
                log.Error(e.ToString());
                return(req.CreateResponse(HttpStatusCode.Forbidden, new { Message = e.Message }));
            }
            catch (LineResponseException e)
            {
                log.Error(e.ToString());
                var debugUser = ConfigurationManager.AppSettings["DebugUser"];
                if (!string.IsNullOrEmpty(debugUser))
                {
                    await LineMessagingClient.PushMessageAsync(debugUser, e.ResponseMessage.ToString());
                }
            }
            catch (Exception e)
            {
                log.Error(e.ToString());
                var debugUser = ConfigurationManager.AppSettings["DebugUser"];
                if (!string.IsNullOrEmpty(debugUser))
                {
                    await LineMessagingClient.PushMessageAsync(debugUser, e.ToString());
                }
            }
            return(req.CreateResponse(HttpStatusCode.OK));
        }