Wolfram Language

Channel Framework

Instant Messaging with Arbitrary Content

In a desktop session, load a package that creates an instant messaging demo channel ("WIM") and start listening on it.

In[1]:=
Click for copyable input
Needs["DemoChannels`WIM`"]

Create your WIM channel and start listening on it.

In[2]:=
Click for copyable input
channel = CreateWIMChannel[]
Out[2]=
In[3]:=
Click for copyable input
listener = ChannelListen[channel]
Out[3]=

Send yourself a WIM, and notice your message in a new dialog notebook.

In[4]:=
Click for copyable input
ChannelSend["WIM", "Hi there."]
Out[4]=
Out[5]=

Attach the current notebook to a message.

In[6]:=
Click for copyable input
ChannelSend["WIM", {"Sending a notebook.", InputNotebook[]}]
Out[6]=
Out[7]=

Other users can send you a WIM by referencing your fully qualified channel.

In[8]:=
Click for copyable input
yourWIM = $WolframID <> ":WIM"
Out[8]=
In[9]:=
Click for copyable input
ChannelSend[yourWIM, "hello"]
Out[9]=

Or your WIM URL.

In[10]:=
Click for copyable input
listener["URL"]
Out[10]=
In[11]:=
Click for copyable input
listener["URL"]; ChannelSend[%, "another message"]
Out[11]=

Anyone can also send you a message from a web browser (or any other HTTP client) by making an HTTP request to the following URL.

In[12]:=
Click for copyable input
URLBuild[listener["URL"], {"operation" -> "send", "Message" -> "yet another message"}]
Out[12]=
In[13]:=
Click for copyable input
URLBuild[listener["URL"], {"operation" -> "send", "Message" -> "yet another message"}]; URLFetch[%]
Out[13]=

To reply to the incoming messages from other users, authorize communication on user channels.

In[14]:=
Click for copyable input
Unprotect[$AllowExternalChannelFunctions]; $AllowExternalChannelFunctions = True;

Stop listening and restore the security setting.

In[15]:=
Click for copyable input
RemoveChannelListener[listener]
Out[15]=
In[16]:=
Click for copyable input
$AllowExternalChannelFunctions = False; Protect[$AllowExternalChannelFunctions];

Related Examples

de es fr ja ko pt-br ru zh