Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
halr9000 #1
Member since Jan 2008 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Need help getting a PowerShell example working
This is what I have so far, having translated it from the C# Send Message example.  No message is received, but I get no errors either.  I have a feeling I didn't invoke the Send method correctly.  Here is the C# line I'm having trouble with:

  1. xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?")); };

[Update: I worked with Alex on this and here is code that works pretty well, but not against all servers.  You can see the various options I was playing with, they may help in your situation.  The key was to loop for the state of $xmppClient.Authenticated.]

And the PowerShell code:

  1. function Send-XmppMessage {
  2.     param (
  3.         $From,
  4.         $Password,
  5.         $To,
  6.         $Body
  7.     )
  8.    
  9.     # This function reads a string from the host while masking with *'s.
  10.     function Read-HostMasked( [string]$prompt="Password" ) {
  11.         $password = Read-Host -AsSecureString $prompt;
  12.         $BSTR = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password);
  13.         $password = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($BSTR);
  14.         [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR);
  15.         return $password;
  16.     }
  17.    
  18.     [void][reflection.assembly]::LoadFrom( $(resolve-path $profiledir\Assemblies\agsXMPP.dll) )
  19.     $jidSender      = New-Object agsxmpp.jid( $From )
  20.     $jidReceiver    = New-Object agsxmpp.jid ( $To )
  21.     $xmppClient     = New-Object agsxmpp.XmppClientConnection( $jidSender.Server )
  22.     $Message        = New-Object agsXMPP.protocol.client.Message( $jidReceiver, $Body )
  23.     #$xmppClient.UseSSL                     = $FALSE
  24.     #$xmppClient.UseStartTLS                = $FALSE
  25.     $xmppClient.AutoAgents                  = $FALSE
  26.     $xmppClient.AutoRoster                  = $FALSE
  27.     $xmppClient.AutoResolveConnectServer    = $TRUE
  28.     if ( !$password ) { $password = Read-HostMasked }
  29.     $xmppClient.Open( $jidSender.User, $Password )
  30.         while ( !$xmppClient.Authenticated ) {
  31.         Write-Host $xmppClient.XmppConnectionState
  32.         Start-Sleep 1
  33.     }
  34.     #$xmppClient.SendMyPresence()
  35.     $xmppClient.Send( $Message )
  36.     Start-Sleep 1
  37.     $xmppClient.Close()
  38. }
Author, TechProsaic (http://halr9000.com)
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Webmaster, Psi (http://psi-im.org)
This post was edited on 2008-01-07, 20:17 by halr9000.
Avatar
Alex #2
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I have to figure out how to invoke events/callbacks with the PowerShell to improve this code.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS