kwailo888 / AxolotlTestApp

9 stars 3 forks source link

SendMessageBroadcastLocation #20

Closed ffwblueshadow closed 8 years ago

ffwblueshadow commented 8 years ago

Hi, thanks for you work. I try to add the function public void SendMessageBroadcastLocation(string[] to, string name, double lat, double lon) { this.SendMessageBroadcast(to, new FMessage(string.Empty, true) { location_details = name, media_wa_type = FMessage.Type.Location, latitude = lat, longitude = lon }); } But i don't know how to change the function "SendMessageBroadcast"

public void SendMessageBroadcast(string[] to, FMessage message)
        {
            if (to != null && to.Length > 0 && message != null && !string.IsNullOrEmpty(message.data))
            {
                ProtocolTreeNode child;
                if (message.media_wa_type == FMessage.Type.Undefined)
                {
                    //text broadcast
                    child = new ProtocolTreeNode("body", null, null, WhatsApp.SYSEncoding.GetBytes(message.data));
                }
                else
                {
                   throw new NotImplementedException();
                }

                List<ProtocolTreeNode> toNodes = new List<ProtocolTreeNode>();
                foreach (string target in to)
                {
                    toNodes.Add(new ProtocolTreeNode("to", new KeyValue[] { new KeyValue("jid", WhatsAppApi.WhatsApp.GetJID(target)) }));
                }

                ProtocolTreeNode broadcastNode = new ProtocolTreeNode("broadcast", null, toNodes);
                Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                ProtocolTreeNode messageNode = new ProtocolTreeNode("message", new KeyValue[] {
                    new KeyValue("to", unixTimestamp.ToString() + "@broadcast"),
                    new KeyValue("type", message.media_wa_type == FMessage.Type.Undefined?"text":"media"),
                    new KeyValue("id", message.identifier_key.id)
                }, new ProtocolTreeNode[] {
                    broadcastNode,
                    child
                });
                this.SendNode(messageNode);
            }

        }

Maybe someone can help me :) Thanks

kwailo888 commented 8 years ago

take a look at SendMessageWithMedia and see ow it was implemented there . you can extract the relevant parts and create a new function to broadcast your location message