How to Remotely Send a Message to a Group of Contacts

This sample demonstrates how to remotely send a message to a group of contacts. This can be useful when you need to send bulk SMS from a remote location (e.g. from your mobile phone or via email).

File ForwardMessage.vbs used in this sample is located in the folder:

    C:\Program Files\CodeSegment\SMS Studio\Samples\InfoService

This script receives the pipe name, the ID of the account from which the messages should be sent and the text of the message. The first word of the message text (separated with a space character from the rest of the text) should be the name of the group of recipients or the phone number of the single recipient. For example, a message text may contain [Friends] Hello there!, assuming that you have a group named Friends in the Address Book.

The contents of the ForwardMessage.vbs file:

'-------------------------------------------------------------------------------------------------------------------------------
' This script demonstrates how to forward a message using Info Service Named Pipe
' After this script is executed forwarded messages will appear in the Outbox window.
' WARNING: Error checking omitted for clarity.
'
' Use the following application parameters in the Info Rule dialog:
' "%PipeName%" "ACCOUNT_ID" "%MsgText%"
' The ACCOUNT_ID parameter should be taken (Copy&Paste) from the Edit Connection dialog - Account tab - AccountID field
'-------------------------------------------------------------------------------------------------------------------------------

if WScript.Arguments.Count = 3 then
   
    ' Collect arguments
    PipeName = WScript.Arguments(0)                          ' Pipe name
    AccountID = WScript.Arguments(1)                         ' The ID of the account from which messages should be sent
    MsgText = Trim(WScript.Arguments(2))                     ' Message text
   
    if PipeName <> "" then                                   ' Pipe name must be specified in the Info Setup dialog
       
        Pos = InStr(MsgText," ")
        if Pos > 0 then                                      ' Message must contain recipient
           
            Recipient = Left(MsgText,Pos-1)
            MsgText = Mid(MsgText,Pos)
           
            'Encode CR and LF characters
            MsgText = Replace(MsgText,vbCr,"%0D")
            MsgText = Replace(MsgText,vbLf,"%0A")
           
            ' Open the pipe instance
            set fso=CreateObject("Scripting.FileSystemObject")
            set pipe=fso.CreateTextFile("\\.\pipe\" & PipeName)
           
            ' Forward the message
            pipe.WriteLine("AccountID:" & AccountID)
            pipe.WriteLine("To:" & Recipient)
            pipe.WriteLine("Encoded:" & MsgText)
            pipe.WriteLine("<Send>")                         ' Send the message
           
            pipe.Close
           
            WScript.Quit(0)                                  ' Success
           
        else
           
            WScript.Quit(1)                                  ' Error
           
        end if
       
    else
       
        MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Forward Message Sample"
        WScript.Quit(1)                                      ' Error
       
    end if
   
else
   
    MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Forward Message Sample"
    WScript.Quit(1)                                          ' Error
   
end if

'-------------------------------------------------------------------------------------------------------------------------------
' Copyright (c) 2002-2006 CodeSegment. All rights reserved.                                          http://www.codesegment.com/
'-------------------------------------------------------------------------------------------------------------------------------

How to run this sample

  1. Click the New button on the main toolbar and select the Info service option in the New Service dialog.
  2. Click the Setup button on the main toolbar to display the Info Setup dialog.
  3. In the General tab of the Info Setup dialog click the Add button to display the Add Rule dialog.
  4. In the General tab of the Add Rule dialog enter the following parameters:
    Name: Forward Message
    Pattern: *
    Action: Execute external application
  5. In the Execute tab of the Add Rule dialog enter the following parameters:
    External application: ForwardMessage.vbs - use the selection button ( ... ) to locate and select the external application.
    Application parameters: "%PipeName%" "ACCOUNT_ID" "%MsgText%"
  6. Note that ACCOUNT_ID parameter should be taken from the Edit Connection dialog / Account tab / Account ID field.
  7. Click the Add button to close the Add Rule dialog.
  8. In the Advanced tab of the Info Setup dialog enter the name of the pipe:
    Pipe name: RemotePipe
  9. Click the OK button to close the Info Setup dialog.
  10. Click the Start button on the main toolbar to start the Info service.
  11. Use Tools / Receive Message option in the main menu to display the Receive Message dialog. Fill in the Text field (e.g. +1234567 Hello! or [Friends] Hello!) and click the Receive button. The Info service will receive this message and run the ForwardMessage.vbs application which will place outgoing messages in the Outbox.

Related topics

Named Pipe

 

Copyright © 2002-2007 CodeSegment. All rights reserved.

   www.codesegment.com