> The script should only be able to sendMessage to the public chat. Does current API allow me to do that?
API has allowed it sionce I think version 3.0. In Skype4Com wrapper the public chats part of the API was only included in version 1.0.28 (available as download on DevZone). With 1.0.28 you can do it as follows (Delphi example again but its interacting with ActiveX anyway so should be easy re-use in another languages):
CODE
//------------------------------------------------------------------------------
// Skype API, Public Chats Test
// for Delphi, using Skype4Com library
//
// Tested with Delphi 5, Skype4Com v.1.0.28, Skype v.3.5.0.214
//
// NB! This example will NOT work properly with Skype4Com versions
// below 1.0.28.
//
// To use the code in this example:
// 1. Create new application. A form named Form1 should be created automatically
// 2. Drag and drop following 2 components onto Form1:
// 2.1 Standard Memo component named Memo1
// 2.2 Two standard Button components named Button1 and Button2
// 3. Copy & paste this exaple into Form1's code editor.
// 4. Go to Form view and link following events:
// 4.1 Form1.OnCreate -> FormCreate
// 4.2 Button1.OnClick -> Button1Click
// 4.2 Button2.OnClick -> Button2Click
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SKYPE4COMLib_TLB, OleServer;
Const Protocol = 8;
// NB! Change this constant to your own public chat BLOB
// To get a public chat BLOB, create a public chat in Skype UI, then:
// 1. From chat window menu: Options / Promote chat
// 2. click on Copy link on clipboard
// 3. paste the link here
// 4. from the link, take everything that follows substring '&blob=', thats the BLOB
// 5. Assign that BLOB to MyBLOB constant.
Const MyBLOB = 'F-0u9S6LhayaPzpJNxRVhjFyVK_Yw-7OtS3fQn14C-xTBp92kKUTuY39sDSQ8F7v';
Type
TForm1 = Class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Procedure FormCreate(Sender: TObject);
Procedure OnSkypeAttachmentStatus(Sender: TObject; Status: TOleEnum);
Procedure OpenPublicChat(Sender: TObject);
Procedure SendMessage (Sender: TObject);
Procedure OnSkypeChatMembersChanged (ASender: TObject;
const pChat: IChat;
const pMembers: IUserCollection);
Procedure OnSkypeChatMemberRoleChanged (ASender: TObject;
const pMember: IChatMember;
Role: TChatMemberRole);
Private
Skype : TSkype;
MyPublicChat : IChat;
End;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.OpenPublicChat (Sender : TObject);
Begin
Try
MyPublicChat := Skype.FindChatUsingBlob(MyBLOB);
Except
MyPublicChat := Skype.CreateChatUsingBlob(MyBLOB);
End;
MyPublicChat.Join;
MyPublicChat.OpenWindow;
End;
Procedure TForm1.SendMessage (Sender : TObject);
Begin
Try
MyPublicChat.SendMessage('ping!!');
Except
Memo1.Lines.Add('Cannot ping. Is the chat open? I think it isn''t..');
End;
End;
Procedure TForm1.FormCreate(Sender: TObject);
Begin
Skype := TSkype.Create(Self);
Skype.OnAttachmentStatus := OnSkypeAttachmentStatus;
Skype.OnChatMembersChanged := OnSkypeChatMembersChanged;
Skype.OnChatMemberRoleChanged := OnSkypeChatMemberRoleChanged;
Caption := 'Public Chat Test';
Memo1.Clear;
Memo1.Align := alClient;
Button1.Align := alBottom;
Button1.Caption := 'Connect';
Button2.Align := alBottom;
Button2.Caption := 'Ping';
// Attaching to Skype
Skype.Attach(Protocol, False);
End;
Procedure Log (S : String);
Begin
Form1.Memo1.Lines.Add(S);
End;
Procedure TForm1.OnSkypeAttachmentStatus(Sender: TObject; Status: TOleEnum);
Begin
Memo1.Lines.Add('Skype attatchment status: ' + Skype.Convert.AttachmentStatusToText(Status));
if Status = apiAttachAvailable Then Skype.Attach(Protocol, False);
End;
Procedure TForm1.OnSkypeChatMembersChanged (ASender: TObject;
const pChat: IChat;
const pMembers: IUserCollection);
Begin
Log('OnSkypeChatMembersChanged event fired for ' +
pChat.FriendlyName +
'. New usercount: ' +
IntToStr(pMembers.Count));
End;
Procedure TForm1. OnSkypeChatMemberRoleChanged (ASender: TObject;
const pMember: IChatMember;
Role: TChatMemberRole);
Var S : String;
Begin
Log('OnSkypeChatMemberRoleChanged event fired');
Case Role of
$FFFFFFFF : S := 'MemberRoleUnknown';
0 : S := 'MemberRoleCreator';
1 : S := 'MemberRoleMaster';
2 : S := 'MemberRoleHelper';
3 : S := 'MemberRoleUser';
4 : S := 'MemberRoleListener';
5 : S := 'MemberRoleApplicant';
End;
Log (pMember.Handle + ' role: ' + S);
End;
End.