This is very close to working, but I think some tweaking needs to be done to the way I'm calling the Send() method. I've run out of time for now to work on it, but maybe someone else can pick it up. The line from the SDK examples I'm having trouble translating from C# is this:
xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?"
); };
As you can see below, I did not use the same constructor as they did but it is valid. I don't know what to do with the delegate bits and I'm wondering if there needs to be a while loop to look for xmpp.OnLogin or some property that says we're connected.
function Send-XmppMessage {
param (
$From,
$Password,
$To,
$Body
)
# This function reads a string from the host while masking with *'s.
function Read-HostMasked( [string]$prompt="Password" ) {
$password = Read-Host -AsSecureString $prompt;
$BSTR = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password);
$password = [System.Runtime.InteropServices.marshal]:
trToStringAuto($BSTR);
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR);
return $password;
}
[void][reflection.assembly]::LoadFrom( $(resolve-path $profiledir\Assemblies\agsXMPP.dll) )
$jidSender = New-Object agsxmpp.jid( $From )
$jidReceiver = New-Object agsxmpp.jid ( $To )
$xmppClient = New-Object agsxmpp.XmppClientConnection( $jidSender.Server )
$Message = New-Object agsXMPP.protocol.client.Message( $jidReceiver, $Body )
if ( !$password ) { $password = Read-HostMasked }
$xmppClient.Open( $jidSender.User, $Password )
$xmppClient.Send( $Message )
$xmppClient.Close()
}