Mensagens instantâneas com conteúdo arbitrário
Em uma sessão de desktop, carregue um pacote que crie um canal de demonstração de mensagem instantânea ("WIM") e como a escutar nele.
In[1]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_34.png)
Needs["DemoChannels`WIM`"]
Crie seu canal WIM e comece a escutar nele.
In[2]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_35.png)
channel = CreateWIMChannel[]
Out[2]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_38.png)
In[3]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_36.png)
listener = ChannelListen[channel]
Out[3]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_39.png)
Envie para você mesmo um WIM, e repare que sua mensagem está em um novo notebook de diálogo.
In[4]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_37.png)
ChannelSend["WIM", "Hi there."]
Out[4]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_40.png)
Out[5]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_41.png)
Anexe o notebook atual a uma mensagem.
In[6]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_38.png)
ChannelSend["WIM", {"Sending a notebook.", InputNotebook[]}]
Out[6]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_42.png)
Out[7]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_43.png)
Outros usuários da Wolfram Langauge podem enviar-lhe um WIM incluindo seu canal totalmente qualificado.
In[8]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_39.png)
yourWIM = $WolframID <> ":WIM"
Out[8]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_44.png)
In[9]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_40.png)
ChannelSend[yourWIM, "hello"]
Out[9]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_45.png)
Ou seu URL de WIM.
In[10]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_41.png)
listener["URL"]
Out[10]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_46.png)
In[11]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_42.png)
listener["URL"];
ChannelSend[%, "another message"]
Out[11]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_47.png)
Qualquer pessoa também pode enviar uma mensagem para você de um navegador web (ou qualquer outro cliente HTTP) criando uma solitação de HTTP o seguinte URL.
In[12]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_43.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}]
Out[12]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_48.png)
In[13]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_44.png)
URLBuild[listener["URL"], {"operation" -> "send",
"Message" -> "yet another message"}];
URLFetch[%]
Out[13]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_49.png)
Para responder às mensagens recebidas de outros usuários, autorize a comunicação nos canais de usuários.
In[14]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_45.png)
Unprotect[$AllowExternalChannelFunctions];
$AllowExternalChannelFunctions = True;
Pare de ouvir e restaure a configuração de segurança.
In[15]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_46.png)
RemoveChannelListener[listener]
Out[15]=
![](assets.pt-br/instant-messaging-with-arbitrary-content/O_50.png)
In[16]:=
![Click for copyable input](assets.pt-br/instant-messaging-with-arbitrary-content/In_47.png)
$AllowExternalChannelFunctions = False;
Protect[$AllowExternalChannelFunctions];