An example how to create a message into internal communication channel using an API.
Please note that internal communication channels can be accessed by users only using new Giosg UI.
Organization id is a uuid string, for example db9f631d-203f-4b73-b32b-73eaf67f2790.
123456789
constapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";// Replace it with your tokenconstme=awaitfetch("https://service.giosg.com/api/v5/users/me",{headers:{Authorization:`Token ${api_token}`,"content-type":`application/json`,},}).then((response)=>response.json());console.info(me);
1 2 3 4 5 6 7 8 910
importrequestsapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn"# Replace it with your tokenheaders={'Authorization':'Token '+api_token}response=requests.get("https://service.giosg.com/api/v5/users/me",headers=headers)response.raise_for_status()data=response.json()print(data)
Let's take a look on current internal communication channels:
1 2 3 4 5 6 7 8 9101112131415161718
constapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";// Replace it with your tokenconstorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790";// Replace it with your organization id// This endpoint returns a paginated collection, so we have to iterate over all pages to get all channelsleturl=`https://service.giosg.com/api/pub/v1/orgs/${organization_id}/channels`;while(url){constdata=awaitfetch(url,{headers:{Authorization:`Token ${api_token}`,"content-type":`application/json`,},}).then((response)=>response.json());console.info(data.results);// It will be next page url or null if there is no next pageurl=data.next;}
1 2 3 4 5 6 7 8 9101112131415161718
importrequestsapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn"# Replace it with your tokenorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790"# Replace it with your organization idheaders={'Authorization':'Token '+api_token}# This endpoint returns a paginated collection, so we have to iterate over all pages to get all channelsurl=f"https://service.giosg.com/api/pub/v1/orgs/{organization_id}/channels"whileurl:response=requests.get(url,headers=headers)response.raise_for_status()data=response.json()print(data['results'])# It will be next page url or null if there is no next pageurl=data['next']
12345678
[{"id":"146ff4d9-ca6f-4486-a9cb-c3a0c513db9b","name":"My super channel name",...},...]
Create a message into internal communication channel¶
1 2 3 4 5 6 7 8 910111213141516171819202122232425
constapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";// Replace it with your tokenconstorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790";// Replace it with your organization idconstchannel_id="146ff4d9-ca6f-4486-a9cb-c3a0c513db9b";// Use `id` attribute from any channel from previous stepconsturl=`https://service.giosg.com/api/pub/v1/orgs/${organization_id}/channels/${channel_id}/messages`;constmessageBody={version:3,chunks:[{type:"text",text:"Hello "},{type:"link",kind:"email",text:"support@giosg.com"},{type:"text",text:"\nHow are you?"},],};constdata=awaitfetch(url,{method:"POST",headers:{Authorization:`Token ${api_token}`,"content-type":`application/json`,},body:JSON.stringify({body:messageBody}),}).then((response)=>response.json());console.info(data);
1 2 3 4 5 6 7 8 910111213141516171819202122
importrequestsapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";# Replace it with your tokenorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790";# Replace it with your organization idchannel_id="146ff4d9-ca6f-4486-a9cb-c3a0c513db9b";# Use `id` attribute from any channel from previous stepheaders={'Authorization':'Token '+api_token}url=f"https://service.giosg.com/api/pub/v1/orgs/{organization_id}/channels/{channel_id}/messages";message_body={"version":3,"chunks":[{"type":"text","text":"Hello "},{"type":"link","kind":"email","text":"support@giosg.com"},{"type":"text","text":"\nHow are you?"},],}response=requests.post(url,headers=headers,json={"body":message_body})response.raise_for_status()data=response.json()
1 2 3 4 5 6 7 8 910111213
{"id":"4ebbb3bf-051a-4cae-ba2b-ac93ee178cf3","created_at":"2021-02-11T12:32:47.079271Z","updated_at":"2021-02-11T12:32:47.079295Z","body":{"version":3,"chunks":[{"type":"text","text":"Hello "},{"type":"link","kind":"email","text":"support@giosg.com"},{"type":"text","text":"\nHow are you?"},]}}
This will create a message:
Create a message with external view to show anything you want¶
constapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";// Replace it with your tokenconstorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790";// Replace it with your organization idconstchannel_id="146ff4d9-ca6f-4486-a9cb-c3a0c513db9b";// Use `id` attribute from any channel from previous stepconsturl=`https://service.giosg.com/api/pub/v1/orgs/${organization_id}/channels/${channel_id}/messages`;constmessageBody={version:3,chunks:[{type:"text",text:"Click me to see an external view"},],externalView:{url:"https://giosg.com",title:"Giosg in Giosg",},};constdata=awaitfetch(url,{method:"POST",headers:{Authorization:`Token ${api_token}`,"content-type":`application/json`,},body:JSON.stringify({body:messageBody}),}).then((response)=>response.json());console.info(data);
1 2 3 4 5 6 7 8 9101112131415161718192021222324
importrequestsapi_token="8ttjj2qbhlej1fes86gqriibc70pku79evgcezpn";# Replace it with your tokenorganization_id="db9f631d-203f-4b73-b32b-73eaf67f2790";# Replace it with your organization idchannel_id="146ff4d9-ca6f-4486-a9cb-c3a0c513db9b";# Use `id` attribute from any channel from previous stepheaders={'Authorization':'Token '+api_token}url=f"https://service.giosg.com/api/pub/v1/orgs/{organization_id}/channels/{channel_id}/messages";message_body={"version":3,"chunks":[{"type":"text","text":"Click me to see an external view"},],"externalView":{"url":"https://giosg.com","title":"Giosg in Giosg",},}response=requests.post(url,headers=headers,json={"body":message_body})response.raise_for_status()data=response.json()
1 2 3 4 5 6 7 8 9101112131415
{"id":"4ebbb3bf-051a-4cae-ba2b-ac93ee178cf3","created_at":"2021-02-11T12:32:47.079271Z","updated_at":"2021-02-11T12:32:47.079295Z","body":{"version":3,"chunks":[{"type":"text","text":"Click me to see an external view"},],"externalView":{"url":"https://giosg.com","title":"Giosg in Giosg",},}}
This will create a message:
It will open an external view with an iframe to a url you provided: