예제 #1
0
        public async Task <Message> BuildMessage(Channel channel, ZaloMessage msg, Customer customer)
        {
            var message_id       = MessageService.FormatId01(channel.business_id, msg.msgid);
            var sender_ext_id    = "";
            var recipient_ext_id = "";

            if (Convert.ToInt64(msg.fromuid) > 0 && msg.fromuid.ToString() != channel.ext_id)
            {
                sender_ext_id    = msg.fromuid.ToString();
                recipient_ext_id = msg.oaid.ToString();
            }
            else
            {
                sender_ext_id    = msg.oaid.ToString();
                recipient_ext_id = msg.touid.ToString();
            }
            if (sender_ext_id.Length < 5)
            {
                return(null);
            }

            var thread_id = ThreadService.FormatId01(channel.business_id, customer.ext_id);

            var timestamp    = msg.timestamp > 9999999999 ? msg.timestamp / 1000 : msg.timestamp;
            var created_time = Core.Helpers.CommonHelper.UnixTimestampToDateTime(timestamp);

            var imageUrl = msg.href;

            if (!string.IsNullOrWhiteSpace(imageUrl) && !imageUrl.Contains("hibaza") && !imageUrl.Contains("firebase"))
            {
                imageUrl = await DownloadToLocalAsync(imageUrl);
            }

            var message = new Domain.Entities.Message
            {
                //"sendmsg"  "sendimagemsg")
                id                  = message_id,
                parent_id           = "",
                parent_ext_id       = "",
                root_ext_id         = "",
                conversation_ext_id = sender_ext_id,
                ext_id              = msg.msgid,
                thread_id           = thread_id,
                thread_type         = "message",
                sender_id           = CustomerService.FormatId01(channel.business_id, sender_ext_id),
                sender_ext_id       = sender_ext_id,
                sender_name         = sender_ext_id == customer.ext_id ? customer.name : channel.name,
                sender_avatar       = sender_ext_id == customer.ext_id ? customer.avatar : "",
                recipient_id        = CustomerService.FormatId01(channel.business_id, recipient_ext_id),
                recipient_ext_id    = recipient_ext_id,
                recipient_name      = recipient_ext_id == channel.ext_id ? channel.name : customer.name,
                recipient_avatar    = recipient_ext_id == channel.ext_id ? "" : customer.avatar,
                author              = CustomerService.FormatId01(channel.business_id, sender_ext_id),
                customer_id         = customer.id,
                message             = msg.message,
                tag                 = "",
                template            = "",
                url                 = imageUrl,
                timestamp           = timestamp,
                updated_time        = created_time,
                created_time        = created_time,
                business_id         = channel.business_id,
                channel_id          = channel.id,
                channel_ext_id      = channel.ext_id,
                channel_type        = channel.type,
                owner_id            = sender_ext_id,
                agent_id            = customer.agent_id,
                type                = msg.@event == "sendimagemsg" ? "image" : "text",
                liked               = false,
                hidden              = false,
                deleted             = false,
                urls                = "[]"
            };

            return(message);
        }