所以我知道这个API很老,而且没有记录,这正是我提出SO问题的原因,所以我想知道如何使用C#
Skype在Skype中选择聊天桌面API,我已经做过一些环顾四周,但大多数人似乎都在使用WinForms
制作他们的应用,我的只是一个简单的控制台应用程序,代码:
Skype Skype = new Skype();
Skype.Attach(5, true);
Skype.Chat.SendMessage("Hello ??");
Parser.Pause();
在运行时,我当然得到一个例外,告诉我我需要选择一个聊天,但我不知道如何做到这一点,我看了here但是那个对我帮助不大。
有没有办法使用特定代码轻松引用聊天?等等......谢谢!
答案 0 :(得分:2)
我构建了这个应该帮助你的片段......
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");