2016-10-14 15 views
1

このAPIはかなり古くてドキュメント化されていないことがわかりました。私はよく質問しています。C#スカイプデスクトップを使用してSkypeでチャットを選択する方法を知りたかったのですAPI、私はいくつかの周りを見ているが、ほとんどの人が自分のアプリを作るためにWinFormsを使用しているように見えるやった、鉱山は単純なコンソールアプリケーション、コードです:実行時にSkype C#APIチャットを選択

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

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

Parser.Pause(); 

、当然のI例外はI私に言ってますチャットを選択する必要がありますが、私はどのようにそれを行うことができるかについてはわかりません、私はhereを見てきましたが、それは私にはあまり役立たなかった。

特定のコードを使用して簡単にチャットを参照する方法はありますか?等...ありがとう!

Chat chat = s.CreateChatWith("name of the user to chat with"); 
chat.SendMessage("test"); 

あなたが作成することができます

私はあなたを助ける必要があり、このスニペットを構築した

答えて

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; 
     } 


    } 
} 

の代わりに、既存のチャットオブジェクトを使用して、あなたはこの方法で新しいチャットオブジェクトを作成することができますグループチャット:

または表示名でグループを取得する方法

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"); 
+0

?これはグループのスクリーンショットの一例です:http://prntscr.com/ctnr41招待状IDまたはグループ名を「majesticsubway」のようにグループを選択できると思っていましたか? :-) – Jek

+0

私は答えを更新します –

+0

@ジェク私は答えを更新しました –