Application sent twice the same message

0

I'm having a new problem with the skype library (skype4com) . In fact they are two problems. I'm doing my application in WindowsForm (C#) .

I made an application to send auto-reply on skype.

private Skype skypeId;
private string resposta = "**********ESTA E UMA RESPOSTA AUTOMATICA**********";

private void Form1_Load(object sender, EventArgs e)
{            
    //captura a instancia do skype
    skypeId = new Skype();
    skypeId.Attach(7, false);

    //Monitor
    skypeId.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skypeId_MessageStatus);

}

public void skypeId_MessageStatus (ChatMessage msg, TChatMessageStatus status)
{
    if(msg.Body != "")
    {
        System.Threading.Thread.Sleep(5000);
        try
        {
            skypeId.SendMessage(msg.Sender.Handle, resposta);
        }
        catch (Exception err)
        { 

        }
    }
}

What happens is that when a message arrives on skype the application sends after 5 seconds twice the message resposta . I already tried to put a variable bool to check and it was the same as below, but it did not work:

public void skypeId_MessageStatus (ChatMessage msg, TChatMessageStatus status)
{
    bool novaMsg = true;
    if(msg.Body != "" && novaMsg == true)
    {
        novaMsg = false;
        System.Threading.Thread.Sleep(5000);
        try
        {
            skypeId.SendMessage(msg.Sender.Handle, resposta);
        }
        catch (Exception err)
        { 

        }
    }
}

Another problem is that only the reply to new people messages is sent, group messages are not answered. I have already seen here in a question from another user that the form of response in chat is thus Ex: msg.Chat.SendMessage("Mensagem"); , however how can I differentiate a normal conversation from a Skype group chat?

    
asked by anonymous 22.04.2016 / 22:41

1 answer

0

In the method that responds to a new message I used a condition to respond:

public void skypeId_MessageStatus (IChatMessage msg, TChatMessageStatus status)
if(status == TChatMessageStatus.cmsReceived)
{
    skype.SendMessage(msg.FromHandle, resp);                 
}

So when a new message is answered it is no longer of type Received TChatMessageStatus.cmsReceived , and checking status does not go into "new message" condition.

    
09.05.2016 / 19:21