Skype C#API选择聊天

Skype C#API选择聊天,c#,console,skype,skype4com,C#,Console,Skype,Skype4com,所以我知道这个API非常古老而且没有文档记录,这正是我提出这么一个问题的原因,所以我想知道如何使用C#Skype桌面API在Skype中选择聊天,我已经四处查看了一些,但大多数人似乎都在使用WinForms来制作他们的应用程序,我的只是一个简单的控制台应用程序,代码: Skype Skype = new Skype(); Skype.Attach(5, true); Skype.Chat.SendMessage("Hello ??"); Parser.Pause(); 在运行时,我当然会遇

所以我知道这个API非常古老而且没有文档记录,这正是我提出这么一个问题的原因,所以我想知道如何使用
C#
Skype桌面API在Skype中选择聊天,我已经四处查看了一些,但大多数人似乎都在使用
WinForms
来制作他们的应用程序,我的只是一个简单的控制台应用程序,代码:

Skype Skype = new Skype();
Skype.Attach(5, true);

Skype.Chat.SendMessage("Hello ??");

Parser.Pause();
在运行时,我当然会遇到一个异常,告诉我需要选择一个聊天,但我不确定如何才能做到这一点,我已经看过了,但这对我没有多大帮助


有没有一种方法可以使用特定代码轻松引用聊天记录?等谢谢

我构建了这个片段,它应该可以帮助您

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using SKYPE4COMLib;

namespace skypeExperiment
{
    class Program
    {   
        static void Main(string[] args)
        {
            Skype s = new Skype();
            s.Attach();
            if (!s.Client.IsRunning)
            {
                // start minimized with no splash screen
                s.Client.Start(true, true);
            }

            // wait for the client to be connected and ready
            //you have to click in skype on the "Allow application" button which has popped up there
            //to allow this application to communicate with skype
            s.Attach(6, true);

            //this will print out all the chat names to the console
            //it will enumerate all the chats you've been in
            foreach (Chat ch in s.Chats)
            {
                Console.WriteLine(ch.Name);
            }

            //pick one chat name of the enumerated ones and get the chat object
            string chatName = "#someskypeuser/someskypeuser;9693a13447736b9";
            Chat chat = GetChatByName(s, chatName);
            //send a message to the selected chat
            if (chat != null)
            {
                chat.SendMessage("test");
            }
            else
            {
                Console.WriteLine("Chat with that name was not found.");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        private static Chat GetChatByName(Skype client, string chatName)
        {
            foreach (Chat chat in client.Chats)
            {
                if (chat.Name == chatName) return chat;
            }
            return null;
        }


    }
}
您可以使用方法创建新的聊天对象,而不是使用现有的聊天对象

Chat chat = s.CreateChatWith("name of the user to chat with");
chat.SendMessage("test");
您可以通过以下方式创建群聊:

Group mygroup = s.CreateGroup("mygroup");
mygroup.AddUser("user1");
mygroup.AddUser("user2");
Chat myGroupChat = s.CreateChatMultiple(mygroup.Users);
myGroupChat.SendMessage("test");
或创建方法以按显示名称检索组

private static Group GetGroupByDisplayName(Skype client, string groupDisplayName)
{
    foreach (Group g in client.Groups)
    {
        if (g.DisplayName == groupDisplayName)
        {
            return g;
        }
    }
    return null;
}
然后像这样使用它:

Group majesticSubwayGroup = GetGroupByDisplayName("majesticsubway"); 
Chat majesticSubwayGroupChat = s.CreateChatMultiple(majesticSubwayGroup.Users);
majesticSubwayGroupChat.SendMessage("test");

那我们一起聊聊怎么样?这是一个组的示例屏幕截图:我想它可以通过邀请ID或组名来选择组,如
majesticsubway
?:-)谢谢,让我试试看!