This project is read-only.
Project Description
A simple helper library and scripts that work with agsXMPP to allow you to send and receive messages via Jabber.

agsXmpp is a GPL .Net Xmpp library that is a project of AG Software -- they in no way are affiliated with PoshXmpp.

Here's a simple example ... don't forget you have to put both DLLs in the same place, and use InstallUtil PoshXmpp.dll and Add-PsSnapin PoshXmpp to get PoshXmpp loaded and ready
$jaykul = ""

# you'll be prompted ... and you'll have to enter a jabber login & password
# you could also pass in an HTTP polling server here, like: 
PoshXmpp\New-Client (Get-Credential)
PoshXmpp\Send-Message $jaykul "Hi there Joel!"

# You'll be sitting, waiting for messages ... press any key to continue
PoshXmpp\Receive-Message -Loop

# This will make sure you're logged off ...

The $PoshXmppClient object is created by the New-Client cmdlet, which also returns it, so you can store it in a different variable in case you want to log into multiple servers. You can pass the -Client parameter to any of the commands, or they will use the default $PoshXmppClient client. If it becomes disconnected, you'll get an error, and can safely re-run New-Client.

Try this one, to listen to IRC (you need Out-Voice)

param (
    $JabberId = $( Read-Host "Bot's Jabber ID" )
   ,$Password = $( Read-Host "Bot's Password" -asSecure)
   ,$Chat[] = @("") # Some IRC channels to join!
   ,$ChatNick = $("PowerBot$((new-object Random).Next(0,9999))")  # Your nickname in IRC

$global:PoshXmppClient = 
PoshXmpp\New-Client $JabberId $Password #
foreach($room in $Chat) {
   PoshXmpp\Connect-Chat $room $ChatNick

while(!$Host.UI.RawUI.KeyAvailable) {
   PoshXmpp\Receive-Message -All | foreach-object {
      "{0}-{1} said: {2}" -f ($_.From.User -split "%")[0], $_.From.Resource, $_.Body | Out-Voice -Wait -Pass
   [Threading.Thread]::Sleep( 100 )

PoshXmpp\Disconnect-Chat $Chat $ChatNick

Other cmdlets so far

  • New-Client -- create the initial connection -- errors if it can't log in
  • Add-Contact -- adds a contact, and/or accepts one who's added you
  • Get-Contact -- list or search your online contacts, takes a wildcard JabberId parameter
  • Send-Message -- takes the JabberId and a message (I'll fix this up later to take the message from the pipeline so you could use it to transfer text files)
  • Receive-Message -- read a message you've received. Has -All and -Loop parameters that let you read all messages you've received so far, or loop and wait for new messages.
  • Connect-Chat -- connect to MUC chats: try "" to connect to the PowerShell IRC channel. NOTE: messages from these come the same way as regular chat messages... you have to Receive-Message to see anything. You could Receive-Message -Loop > log.txt ....
  • Disconnect-Chat -- disconnect from a MUC...
  • Start-Chat -- an attempt at an interactive chat on the command-line. Not very good.

Note that all of these cmdlets actually use methods exposed on the XmppClient object that the New-Client creates, or on it's members (particularly on the MessageManager, ContactManager, and ChatManager members). You can do even more than this using PowerShell script with those objects ...

Last edited Jan 12, 2008 at 3:59 PM by Jaykul, version 7