One very cool thing about the Snom phones is that they are configurable in very many ways, and can fetch their configuration from the Asterisk server automatically. Once you find a setting that's useful for all, simply set it in the provisioning profile and let the phones reboot - and all have the new config setting.
One of the phone's features is calling an HTTP URL when something happens, e.g. start of an incoming or outgoing call, or connecting/disconnecting of the call. My self-assigned task now was to get chat notifications whenever a call comes in.
Unfortunately, mod_post_msg only supported plain text messages - but I wanted to be able to link the names of the incoming caller to our internal address book, and also provide one-click redial/callback functionality via tel: URLs.
Prosody is written in Lua, a scripting language often used in games. With the help of the prosody MUC channel it was easy to extend the plugin with support for HTML messages. My patch got merged and can be used by everyone now.
Sending messages via PHP
When sending a HTML XMPP message, you should always provide a plain text message as fallback for clients that do not support, or whose users do not want to display HTML content. Apart from that, sending the message via a POST request is not hard:
<?php $xmppUser = 'firstname.lastname@example.org'; $xmppPass = 'FIXME'; $xmppTarget = 'email@example.com'; $callerName = 'FIXME'; $adrLink = 'https://FIXME'; $telLink = 'tel:FIXME'; $textMsg = 'Incoming call from ' . $callerName; $htmlMsg = 'Incoming call from ' . '<a href="' . htmlspecialchars($adrLink) . '">' . htmlspecialchars($callerName) . '</a>' . ' <a href="' . htmlspecialchars($telLink) . '">' . '☎</a>'; $postMsg = 'to=' . urlencode($xmppTarget) . '&type=chat' . '&body=' . urlencode($textMsg) . '&html=' . urlencode( '<body xmlns="http://www.w3.org/1999/xhtml">' . $htmlMsg . '</body>body>' ); $ctx = stream_context_create( array( 'http' => array( 'method' => 'POST', 'header' => array( 'Content-type: application/x-www-form-urlencoded', 'Authorization: Basic ' . base64_encode($xmppUser . ':' . $xmppPass), ), 'content' => $postMsg ) ) ); file_get_contents('http://xmpp.example.org:5280/msg/', false, $ctx); ?>
The result will look similar to this: