コード例 #1
0
 public IActionResult WebhookPost([FromBody] FacebookWebhookData obj)
 {
     try
     {
         //add remove like image
         //var p = JsonConvert.SerializeObject(obj);
         //p = p.Replace(_appSettings.BaseUrls.Api, "");
         //obj = JsonConvert.DeserializeObject<FacebookWebhookData>(p);
         _logService.Create(new Log {
             name = "Webhook2", message = "Webhook3", details = JsonConvert.SerializeObject(obj)
         });
         _facebookService.SaveWebhookData("", "", obj, true);
         return(Ok());
     }
     catch (Exception ex)
     {
         if (obj.@object == "page")
         {
             DateTime now  = DateTime.UtcNow;
             Node     node = new Node
             {
                 type         = "facebook.webhook",
                 created_time = now,
                 timestamp    = Core.Helpers.CommonHelper.DateTimeToUnixTimestamp(now),
                 data         = JsonConvert.SerializeObject(obj)
             };
             _nodeService.CreateNode(node);
         }
         _logService.CreateAsync(new Log {
             name = "Webhook calledback", message = ex.Message, details = JsonConvert.SerializeObject(ex.StackTrace)
         });
         throw ex;
     }
 }
コード例 #2
0
ファイル: HotlineService.cs プロジェクト: hibaza/Hibaza.Mida
        public async Task <dynamic> SavePhoneHookData(Phone data)
        {
            try
            {
                if (data == null || string.IsNullOrWhiteSpace(data.customer_phone))
                {
                    return new { status = false }
                }
                ;

                var channel  = _channelService.GetById(data.business_id, data.channel_id);
                var business = _businessService.GetById(data.business_id);

                var customer = await CreateCustomer(data, business, channel);

                if (customer == null)
                {
                    return new { status = false }
                }
                ;
                var thread = await CreateThread(data, customer, business, channel);

                var messager = await CreateMessage(data, thread, customer, business, channel);


                if (customer != null)
                {
                    customer.active_thread = JsonConvert.SerializeObject(thread);

                    customer.agent_id = data.agent_id;
                }
                if (customer != null && thread != null && messager != null)
                {
                    _customerService.CreateCustomer(customer, true);
                    _threadService.CreateThread(thread, true);
                    _messageService.CreateMessage(data.business_id, messager, true);

                    return(new
                    {
                        type = "upsert_hibaza",
                        data = new
                        {
                            status = true,
                            customer_id = customer.id,
                            thread_id = thread.id,
                            message_id = messager.id,
                            agent_id = data.agent_id
                        }
                    });
                }
                else
                {
                    return(new
                    {
                        type = "upsert_hibaza",
                        data = new
                        {
                            status = false,
                            customer_id = customer.id,
                            thread_id = thread.id,
                            message_id = messager.id,
                            agent_id = data.agent_id
                        }
                    });
                }


                //if (string.IsNullOrWhiteSpace(data.business_id) || string.IsNullOrWhiteSpace(data.channel_id))
                //{
                //    var customers = await _customerService.GetCustomerFromPhone(data.customer_phone);
                //    if (customers != null && customers.Count == 1)
                //    {
                //        data.business_id = customers[0].business_id;
                //        data.channel_id = customers[0].channel_id;
                //    }

                //    if (customers != null && customers.Count > 1)
                //    {
                //        var business_id = customers[0].business_id;
                //        var channel_id = customers[0].channel_id;
                //        foreach (var cus in customers)
                //        {
                //            if (string.IsNullOrWhiteSpace(cus.business_id) && cus.business_id != business_id)
                //            {
                //                business_id = "";
                //                break;
                //            }

                //        }
                //        if (!string.IsNullOrWhiteSpace(business_id))
                //        {
                //            data.business_id = business_id;
                //            data.channel_id = channel_id;
                //        }
                //    }

                //}
                //if (string.IsNullOrWhiteSpace(data.business_id))
                //{
                //    return new
                //    {
                //        type = "upsert_hibaza",
                //        data = new
                //        {
                //            status = false,
                //            customer_id = "",
                //            thread_id = "",
                //            message_id = "",
                //            agent_id = data.agent_id
                //        }
                //    };
                //}
            }
            catch (Exception ex) {
                _logService.CreateAsync(new Log {
                    name = "Webhook hotline..", message = ex.Message, details = JsonConvert.SerializeObject(ex.StackTrace)
                });

                return(null);
            }
        }