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](assets.en/instant-messaging-with-arbitrary-content/In_34.png)
Needs["DemoChannels`WIM`"]
Create your WIM channel and start listening on it.
In[2]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_35.png)
channel = CreateWIMChannel[]
Out[2]=
![](assets.en/instant-messaging-with-arbitrary-content/O_38.png)
In[3]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_36.png)
listener = ChannelListen[channel]
Out[3]=
![](assets.en/instant-messaging-with-arbitrary-content/O_39.png)
Send yourself a WIM, and notice your message in a new dialog notebook.
In[4]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_37.png)
ChannelSend["WIM", "Hi there."]
Out[4]=
![](assets.en/instant-messaging-with-arbitrary-content/O_40.png)
Out[5]=
![](assets.en/instant-messaging-with-arbitrary-content/O_41.png)
Attach the current notebook to a message.
In[6]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_38.png)
ChannelSend["WIM", {"Sending a notebook.", InputNotebook[]}]
Out[6]=
![](assets.en/instant-messaging-with-arbitrary-content/O_42.png)
Out[7]=
![](assets.en/instant-messaging-with-arbitrary-content/O_43.png)
Other users can send you a WIM by referencing your fully qualified channel.
In[8]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_39.png)
yourWIM = $WolframID <> ":WIM"
Out[8]=
![](assets.en/instant-messaging-with-arbitrary-content/O_44.png)
In[9]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_40.png)
ChannelSend[yourWIM, "hello"]
Out[9]=
![](assets.en/instant-messaging-with-arbitrary-content/O_45.png)
Or your WIM URL.
In[10]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_41.png)
listener["URL"]
Out[10]=
![](assets.en/instant-messaging-with-arbitrary-content/O_46.png)
In[11]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_42.png)
listener["URL"];
ChannelSend[%, "another message"]
Out[11]=
![](assets.en/instant-messaging-with-arbitrary-content/O_47.png)
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](assets.en/instant-messaging-with-arbitrary-content/In_43.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}]
Out[12]=
![](assets.en/instant-messaging-with-arbitrary-content/O_48.png)
In[13]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_44.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}];
URLFetch[%]
Out[13]=
![](assets.en/instant-messaging-with-arbitrary-content/O_49.png)
To reply to the incoming messages from other users, authorize communication on user channels.
In[14]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_45.png)
Unprotect[$AllowExternalChannelFunctions];
$AllowExternalChannelFunctions = True;
Stop listening and restore the security setting.
In[15]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_46.png)
RemoveChannelListener[listener]
Out[15]=
![](assets.en/instant-messaging-with-arbitrary-content/O_50.png)
In[16]:=
![Click for copyable input](assets.en/instant-messaging-with-arbitrary-content/In_47.png)
$AllowExternalChannelFunctions = False;
Protect[$AllowExternalChannelFunctions];