Demo Channel: Word of the day

Our 'Word of the day' demo channel sends toasts with content made up of five toast elements combined into one: four text blocks and a URL. We break down the different elements below.

Note: the alert at the top is not part of the toast content - it is the toast alert. The toast alert is the push notification message that subscribers receive. This is automatically added as a headline at the top of the toast.

Demo channel 2

The text blocks

Text is shown with the type set to 'text' and the text you want to show set in 'text'. You can optionally set a text style by setting the style to one of 'headline', 'subhead', 'body' or 'footnote'. The default style is 'body'.

In this example we use four different text blocks: three with 'body' styles and one with 'subhead' style.

                  
  { type: "text", style: "body", text: "In pharmacy, a medicine composed of powders or other ingredients, incorporated with some conserve, honey, or syrup, originally made in a form to be licked by the patient." },
  { type: "text", style: "body", text:"Any preparation of a medicine mixed with honey or similar in order to make it more palatable to swallow.\n"},
  { type: "text", style: "subhead", text: "Example usage" },
  { type: "text", style: "body", text: "“Very weakly, sir, since I took the electuary,” answered the patient; “it neighboured ill with the two spoonfuls of pease-porridge and the kirnmilk.”" }
                  
                

The URL

URLs are shown with the type set to 'url'. You must set the url field to the URL link. There is an optional title field you can set to show a text string above the url.

                  
{ type: "url", title: "Source", url: "https://www.wordnik.com" }
                  
                

Bringing it all together

All of the elements of the toast are combined into an array and this is set as the toast content.

                  
const content = [
  { type: "text", style: "body", text: "In pharmacy, a medicine composed of powders or other ingredients, incorporated with some conserve, honey, or syrup, originally made in a form to be licked by the patient." },
  { type: "text", style: "body", text:"Any preparation of a medicine mixed with honey or similar in order to make it more palatable to swallow.\n"},
  { type: "text", style: "subhead", text: "Example usage" },
  { type: "text", style: "body", text: "“Very weakly, sir, since I took the electuary,” answered the patient; “it neighboured ill with the two spoonfuls of pease-porridge and the kirnmilk.”" },
  { type: "url", title: "Source", url: "https://www.wordnik.com" }
];
                  
                

A full toast also includes the toast alert which is the push notification message that subscribers see as well as an optional sound set to one of the sounds ('bell 1', 'bell 2', 'buzz', 'claps', 'glitch', 'klaxon', 'oops', 'register', 'toaster 1', 'toaster 2' or 'yippee'). The complete toast for the word of the day demo channel is below. POST to /channels/{channelUUID}/toasts with this as the POST body:

                  
//POST body
{
  alert: "Electuary",
  sound: "klaxon",
  content: [
    { type: "text", style: "body", text: "In pharmacy, a medicine composed of powders or other ingredients, incorporated with some conserve, honey, or syrup, originally made in a form to be licked by the patient." },
    { type: "text", style: "body", text:"Any preparation of a medicine mixed with honey or similar in order to make it more palatable to swallow.\n"},
    { type: "text", style: "subhead", text: "Example usage" },
    { type: "text", style: "body", text: "“Very weakly, sir, since I took the electuary,” answered the patient; “it neighboured ill with the two spoonfuls of pease-porridge and the kirnmilk.”" },
    { type: "url", title: "Source", url: "https://www.wordnik.com" }
  ]
};
                  
                

Example Javascript code

Here's an example of how you could create this toast using Javascript. If you want to use this code make sure to change {your-api-key} to your API key and {channelUUID} to one of your channels.

                  
const body = {
  alert: "Electuary",
  sound: "klaxon",
  content: [
    { type: "text", style: "body", text: "In pharmacy, a medicine composed of powders or other ingredients, incorporated with some conserve, honey, or syrup, originally made in a form to be licked by the patient." },
    { type: "text", style: "body", text:"Any preparation of a medicine mixed with honey or similar in order to make it more palatable to swallow.\n"},
    { type: "text", style: "subhead", text: "Example usage" },
    { type: "text", style: "body", text: "“Very weakly, sir, since I took the electuary,” answered the patient; “it neighboured ill with the two spoonfuls of pease-porridge and the kirnmilk.”" },
    { type: "url", title: "Source", url: "https://www.wordnik.com" }
  ]
};

const headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {your-api-key}'
};

fetch('https://api.toastworx.com/channels/{channelUUID}/toasts',
{
  method: 'POST',
  headers: headers,
  body: JSON.stringify(body)
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
                  
                

Subscribe to this channel

To subscribe to this channel scan the QR code below in the ToastWorx app.

Demo channel 2