How to Update Contact Information through Named Pipe

This sample demonstrates how to use the named pipe of the Info service to update contact information.

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

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

Upon receiving an incoming message, the script UpdateContact.vbs updates the contact's name, adds the contact into a predefined group and sends back an appropriate reply to the contact.

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: Update Contact
    Pattern: Name *
    Action: Execute external application
  5. In the Execute tab of the Add Rule dialog enter the following parameters:
    External application: UpdateContact.vbs - use the selection button ( ... ) to locate and select the external application.
    Application parameters: "%PipeName%" "%MsgID%" "%MsgFrom%" "%P%" "FRIENDS"
  6. Click the Add button to close the Add Rule dialog.
  7. In the Advanced tab of the Info Setup dialog enter the name of the pipe:
    Pipe name: UpdatePipe
  8. Click the OK button to close the Info Setup dialog.
  9. Click the Start button on the main toolbar to start the Info service.
  10. Use Tools / Receive Message option in the main menu to display the Receive Message dialog. Fill in the Phone and Text fields (e.g. +123456 and Name John) and click the Receive button. The Info service will receive this message and run the UpdateContact.vbs application which will update the contact's name, add him to the group FRIENDS, and send back a reply which will be placed in the Outbox.

Source code

The contents of the UpdateContact.vbs file:

'-------------------------------------------------------------------------------------------------------------------------------
' This script demonstrates how to update contact information in Address Book.
' WARNING: Error checking omitted for clarity.
'
' Use the following application parameters in the Info Rule dialog:
' "%PipeName%" "%MsgID%" "%MsgFrom%" "%P%" "FRIENDS"
'-------------------------------------------------------------------------------------------------------------------------------

if WScript.Arguments.Count = 5 then
    
    ' Collect arguments
    PipeName = WScript.Arguments(0)                             ' Pipe name
    MsgID = WScript.Arguments(1)                                ' Message ID
    ContactPhone = WScript.Arguments(2)                         ' Contact phone
    ContactName = WScript.Arguments(3)                          ' Contact name
    ContactGroup = WScript.Arguments(4)                         ' Contact group
    
    if PipeName <> "" then                                      ' Pipe name must be specified in the Info Setup dialog

        set fso = CreateObject("Scripting.FileSystemObject")
        set pipe = fso.CreateTextFile("\\.\pipe\" & PipeName)   ' Open the pipe instance

        pipe.WriteLine("Contact: " & ContactPhone)
        pipe.WriteLine("Name: " & ContactName)
        pipe.WriteLine("AddGroup: " & ContactGroup)
        pipe.WriteLine("<Update>")                              ' Update contact

        pipe.WriteLine("ReplyToID: " & MsgID)
        pipe.WriteLine("Text: Thanks for updating your name.")
        pipe.WriteLine("<Send>")                                ' Send the message

        pipe.Close                                              ' Close the pipe instance

        WScript.Quit(0)                                         ' Success

    else

        MsgBox "Error: Pipe name is missing.", vbCritical, "SMS Studio Update Contact Sample"
        WScript.Quit(1)                                         ' Error

    end if
    
else
    
    MsgBox "Error: Wrong number of arguments.", vbCritical, "SMS Studio Update Contact Sample"
    WScript.Quit(1)                                             ' Error
    
end if

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

Related topics

Info Rules, Named Pipe

 

Copyright © 2002-2010 CodeSegment. All rights reserved.

   www.codesegment.com