Application sent twice the same message

Asked

Viewed 127 times

0

I’m having a new problem with the skype library (skype4com). Actually there are two problems. I’m doing my application in WindowsForm (C#).

I made an app to send automatic reply in 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 in skype the app sends after 5 seconds twice the message resposta. I tried to put a variable bool to check and was equal below, but 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 this sent the response to new messages from people, group messages is not answered. I’ve seen here in a question from another user that the form of chat response is like this Ex.: msg.Chat.SendMessage("Mensagem");, but how can I differentiate a normal chat from a group chat in skype?

  • A detail I forgot to mention, he won’t stop sending the message until it is viewed. So you keep sending two messages every five seconds!

1 answer

0

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

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 becomes no longer the type Received TChatMessageStatus.cmsReceived, and when checking the status does not enter the condition of "new message".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.