Hack 92. Automate Chat
If you need to send chat messages to a group of people often, why not use this script hack to create a multichat session and send messages to all participants on your behalf. Works with: Windows version of Skype. Sending chat to a lot of people at once can be tedious, and doubly so if you have to do this often, which can be the case for tightknit teams or groups of, say, 10 or more people that use chat a lot. So, the next time you need to send "Progress meeting, 4 p.m. today, room 101" to 50 people, consider automating sending the chat message with this script, chat.vbs. This is also the ideal way to start a multiperson chat session with a lot of participants, as your opening message starts the chat session, adds all participants to that chat session, and then opens the chat window (optional, see script), ready for you to continue chatting. ' File: chat.vbs ' Invoke like this from the command-line: ' chat /u=skypeuser1 /u=skypeuser2 MessageText ' ' Parameters: ' /u=skypeuser1 - Recipients (up to 50) of the chat message have ' their Skype names prefixed with "/u=" ' MessageText - Text for the chat message ' Global variables Dim objShell ' Scripting shell object Dim arrUsers ' Array of users to send Dim objSkypeAPI ' SkypeAPI object Dim objChat ' Chat object Dim bComplete ' Flag to indicate when process is done Dim strChatCmd ' Holds the command to create the chat ' Main script begins here Set objShell = WScript.CreateObject("WScript.Shell") Set objSkypeAPI = WScript.CreateObject("SkypeAPI.Access") objSkypeAPI.ConnectAndWait 15000 bComplete = False ' Count how many users are passed Set objArgs = WScript.Arguments iCount = 0 bUsersFound = False Redim arrUsers(objArgs.Count) For i = 1 to objArgs.Count If (Left(objArgs(i-1), 3) = "/u=") And (Not bInMessage) Then arrUsers(i-1) = Mid(objArgs(i-1), 4) iCount = iCount + 1 If iCount > 50 Then Exit For End If bUsersFound = True ElseIf bUsersFound Then If Not bInMessage Then bInMessage = True Else strMessage = strMessage + " " End If strMessage = strMessage + objArgs(i-1) End If Next ' Prompt the user if the correct parameters weren't sent If iCount > 50 Then objShell.Popup "You are limited to 50 users", 0, _ "Unable to Send Message", 48 ElseIf (iCount = 0) Or (Len(strMessage) = 0) Then objShell.Popup "/u=user1 /u=user2 Message to Send", _ 0, "Broadcast Chat Message Script Usage", 64 Else ' Resize users array Redim Preserve arrUsers(iCount) ' Connect to Skype and wait for finish objSkypeAPI.ConnectAndWait 15000 If objSkypeAPI.Protocol < 4 Then objShell.Popup _ "You must be running a more current version of Skype" Else ' Build and send the chat command strChatCmd = "CHAT CREATE " + Join(arrUsers, ", ") If Right(strChatCmd, 2) = ", " Then strChatCmd = Mid(strChatCmd, 1, Len(strChatCmd)-2) End If strResult = objSkypeAPI.SendBlockingCommand(strChatCmd) ' Parse the result string to get the chat ID sparts = Split(strResult, " ") objSkypeAPI.SendBlockingCommand _ "CHATMESSAGE " + sparts(1) + " " + strMessage ' [Optional] Comment out if you don't want to open ' the chat window objSkypeAPI.SendBlockingCommand "OPEN CHAT " + sparts(1) End If End If As listing a large number of recipients on the command line can be both tedious and error prone, perhaps a better method is to wrap chat.vbs in a batch filesay, team_chat.batas shown here (enter the chat script command and its parameters as one, long, continuous line in the batch file). That way, you can simply invoke it at a command prompt, like this: team_chat "Progress meeting, 4 p.m. today, room 101". REM File: team_chat.bat chat /u=TeamMember1 /u=TeamMember2 /u=TeamMember3 /u=TeamMember4 /u=TeamMember4 /u=TeamMember6…/u=TeamMemberN %1 |