Example #1
0
        private void Skype_MessageStatus(ChatMessage pMessage, TChatMessageStatus aStatus)
        {
            try
            {
                WriteToLog(pMessage.Sender.Handle.ToString() + " " + aStatus.ToString() + " " + pMessage.Body);
                string peer     = pMessage.Chat.DialogPartner;
                string password = GetToken(peer);

                if (aStatus == TChatMessageStatus.cmsSending)
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        // encrypt
                        byte[] msgbytes = SkypeEncryptor.Encrypt(System.Text.Encoding.Unicode.GetBytes(pMessage.Body), password);
                        pMessage.Body = Convert.ToBase64String(msgbytes); // alter the message body
                        WriteToLog("Message encrypted");
                    }
                }
                else if (aStatus == TChatMessageStatus.cmsReceived || aStatus == TChatMessageStatus.cmsRead)
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        // decrypt
                        byte[] msgbytes = Convert.FromBase64String(pMessage.Body);
                        byte[] dec      = SkypeEncryptor.Decrypt(msgbytes, password);
                        string msg      = System.Text.Encoding.Unicode.GetString(dec);
                        WriteToLog("Message decrypted: " + msg);
                        //pMessage.Body = msg; // which is not editable
                    }

                    if (false) // (pMessage.Type == TChatMessageType.cmeSaid)
                    {
                        // Make sure the request came from the mobile account
                        if (pMessage.Sender.Handle.Equals(this._strMobileUser))
                        {
                            // OK, they want to make a change request or send an SMS
                            try
                            {
                                if (pMessage.Body.Length > 3 && pMessage.Body.ToLower().Substring(0, 3).Equals("sms"))
                                {
                                    // This is an SMS request
                                    WriteToLog("SMS request received from " + this._strMobileUser);

                                    // Get the number to SMS to
                                    string[] strBits = pMessage.Body.Split(" ".ToCharArray());
                                    // The number to call is the second argument
                                    // (string is in the format "sms [number] [message]"
                                    string strSmsTarget = strBits[1];
                                    // See if it is a quickswitch number
                                    int intQuickSwitch;
                                    if (int.TryParse(strSmsTarget, out intQuickSwitch) && (intQuickSwitch > 0 && intQuickSwitch < _strShortCutNums.Length))
                                    {
                                        // Yes, this is a quickswitch number. Get the number for it
                                        strSmsTarget = this._strShortCutNums[intQuickSwitch];
                                    }
                                    WriteToLog("Sending SMS to " + strSmsTarget);

                                    // Get the message
                                    string strMessage = pMessage.Body.Substring(pMessage.Body.IndexOf(" ", 4) + 1);
                                    WriteToLog("Message is: " + strMessage);

                                    // Send the SMS
                                    _objSkype.SendSms(strSmsTarget, strMessage, null);
                                    WriteToLog("SMS sent");
                                    pMessage.Chat.SendMessage("SMS sent to " + strSmsTarget);
                                    WriteToLog();
                                }
                                else
                                {
                                    // This is a SkypeOut change request
                                    WriteToLog("Forwarding change request received from " + this._strMobileUser);
                                    string strNewNum = "";
                                    switch (pMessage.Body.ToLower())
                                    {
                                    case "off":
                                        // Switch off forwarding
                                        _objSkype.CurrentUserProfile.CallApplyCF      = false;
                                        _objSkype.CurrentUserProfile.CallForwardRules = "";
                                        break;

                                    case "1":
                                    case "2":
                                    case "3":
                                    case "4":
                                    case "5":
                                        // Quick switch number
                                        strNewNum = this._strShortCutNums[int.Parse(pMessage.Body)];
                                        break;

                                    case "contacts":
                                        // List all the contact numbers
                                        string strContacts = "Quick switch numbers:" + Environment.NewLine;
                                        for (int i = 1; i <= 5; i++)
                                        {
                                            strContacts += i.ToString() + ": " + this._strShortCutNums[i] + Environment.NewLine;
                                        }
                                        WriteToLog("Sending user the list of quick switch numbers");
                                        pMessage.Chat.SendMessage(strContacts);
                                        return;     // Exit out of the function completely

                                    default:
                                        strNewNum = pMessage.Body;
                                        break;
                                    }

                                    if (string.IsNullOrEmpty(strNewNum))
                                    {
                                        pMessage.Chat.SendMessage("Switched off call forwarding");
                                        WriteToLog("Switched off call forwarding");
                                    }
                                    else
                                    {
                                        _objSkype.CurrentUserProfile.CallApplyCF         = true;
                                        _objSkype.CurrentUserProfile.CallForwardRules    = "0,60," + strNewNum;
                                        _objSkype.CurrentUserProfile.CallNoAnswerTimeout = 5;
                                        pMessage.Chat.SendMessage("Reset call forwarding to " + strNewNum);
                                        WriteToLog("Changed SkypeOut forwarding to " + strNewNum);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                pMessage.Chat.SendMessage("Error:  " + ex.Message);
                            }
                        }
                        else
                        {
                            // Someone else? Log and ignore
                            WriteToLog("Chat message received from " + pMessage.Sender.Handle + " was ignored");
                            WriteToLog("Message was: " + pMessage.Body);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }