> ## Documentation Index
> Fetch the complete documentation index at: https://docs-classic.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Channel Output

> Send custom JSON payloads to Channels using Cognigy Code Nodes. Covers api.output and api.say for Webchat, Messenger, and other channels.

With a Code Node, you can output a text message along with a data object by using the following `actions` functions:

```js theme={null}
api.output("<YOUR_TEXT>", {"key": "value" });
// OR
api.say("<YOUR_TEXT>", {"key": "value" });
```

The `data` parameter should take the JSON payload that defines the custom channel message:

```js theme={null}
const jsonPayload = {
 "_cognigy":{
  // Channel Specific Payload 
 }
}

api.say("<YOUR_TEXT>", jsonPayload);
```

See the next sections for the required format.

> [accordion] AI Default Channel
>
> The Cognigy default channel has a specific channel format which you can find more about at [AI default channel format](https://docs-classic.cognigy.com/ai/for-developers/code/ai-default-channel-formats.md).

> [accordion] Alexa
>
> [Alexa Response JSON Reference](https://developer.amazon.com/de/docs/custom-skills/request-and-response-json-reference.html)
>
> ### Example
>
> We'll output a simple card to our contact by using the following snippet:
>
> ```JSON theme={null}
> {
>     "_cognigy": {
>         "_alexa": {
>             "response": {
>                 "shouldEndSession": false,
>                 "card":  {
>                     "type": "Standard",
>                     "title": "Title of the card",
>                     "content": "Content of a simple card",
>                     "text": "Text content for a standard card",
>                     "image": {
>                         "smallImageUrl": "https://url-to-small-card-image",
>                         "largeImageUrl": "https://url-to-large-card-image"
>                     }
>                 }
>             }
>         }
>     }
> }
> ```

> [accordion] Messenger
>
> [Messenger Messaging Reference](https://developers.facebook.com/docs/messenger-platform/send-messages)
>
> For the messenger you can send multiple templates by building a JSON object or by using the **facebook-bot-messenger module**. For further information go to their [GitHub Page](https://github.com/snlangsuan/facebook-bot-messenger#readme).
>
> ### Example
>
> The following snippet will send a simple text message and a quick reply to the contact:
>
> ```JSON theme={null}
> {
>     "_cognigy": {
>         "_facebook": {      
>           "message": {
>             "text": "Hello World",
>             "quick_replies": [
>               {
>                 "content_type": "text",
>                 "condition": "",
>                 "title": "Hi",
>                 "image_url": "",
>                 "payload": "Hi"
>               }
>             ]
>           }
>         }
>     }
> }
> ```
>
> Or you can use the **facebook-bot-messenger** module for building custom json. Here we'll send quick replies to the contact:
>
> ```js theme={null}
> // use facebook-bot-messenger to compile reply
> const builder = new MessengerPlatform.QuickRepliesMessageBuilder('Pick a color:');
> builder.addImageOption('Red', 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED', 'http://petersfantastichats.com/img/red.png')
>        .addImageOption('Green', 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN', 'http://petersfantastichats.com/img/green.png');
>
> // output the reply
> api.output("test", { "_cognigy": { "_facebook": {"message": builder.buildMessage() }}});
> ```

> [accordion] Webchat
>
> The Webchat uses the same format as the **Messenger** but instead of adding the `_facebook` property you have to add `_webchat`.
>
> ### Example
>
> The following example sends a text message and a quick reply to the contact:
>
> ```JSON theme={null}
> {
>     "_cognigy": {
>         "_webchat": {      
>             "message": {
>                 "text": "Hello World",
>                 "quick_replies": [
>                     {
>                         "content_type": "text",
>                         "condition": "",
>                         "title": "Hi",
>                         "image_url": "",
>                         "payload": "Hi"
>                     }
>                 ]
>             }
>         }
>     }
> }
> ```

> [accordion] AI
>
> The default AI channel, which is always selected from the default, uses the almost same format as the webchat above. The only difference is that you type `_default` instead of `_webchat`.
>
> ### Example
>
> The following example sends a text message and a quick reply to the contact:
>
> ```JSON theme={null}
> {
>     "_cognigy": {
>         "_default": {      
>             "message": {
>                 "text": "Hello World",
>                 "quick_replies": [
>                     {
>                         "content_type": "text",
>                         "condition": "",
>                         "title": "Hi",
>                         "image_url": "",
>                         "payload": "Hi"
>                     }
>                 ]
>             }
>         }
>     }
> }
> ```

> [accordion] LINE
>
> [LINE Messaging API](https://developers.line.me/en/reference/messaging-api/#template-messages)
>
> ### Example
>
> The following outputs a simple confirm prompt to the contact:
>
> ```JSON theme={null}
> {
>     "_cognigy": {
>         "_line": {
>                 "type": "template",
>                 "altText": "this is a confirm template",
>                 "template": {
>                     "type": "confirm",
>                     "text": "Are you sure?",
>                     "actions": [
>                         {
>                             "type": "message",
>                             "label": "Yes",
>                             "text": "yes"
>                         },
>                         {
>                             "type": "message",
>                             "label": "No",
>                             "text": "no"
>                         }
>                     ]
>                 }
>         }
>     }
> }
> ```

> [accordion] Smooch
>
> [Smooch messaging API](https://docs.smooch.io/rest/?shell#message-types)
>
> ### Example
>
> The following outputs a simple image to the end user:
>
> ```JSON theme={null}
> {
>     "role": "appMaker",
>     "type": "image",
>     "text": "Hello!",
>     "mediaUrl": "http://example.org/image.jpg",
>     "actions": [{
>         "text": "More info",
>         "type": "link",
>         "uri": "http://example.org"
>     }]
> }
> ```

> [accordion] RingCentral Engage
>
> ### Example
>
> The following outputs a gallery with images to the end user. This example is quite interesting since one needs to [create an attachment for each image](https://developers.ringcentral.com/engage/digital/api-reference/Attachments/createAttachment) using the RingCentral Engage API. The returned **attachmentIds** are inserted in the **Custom JSON** below:
>
> ```JSON theme={null}
> {
>   "command": "structured-content",
>   "body": "",
>   "structuredContent": {
>     "type": "carousel",
>     "items": [
>         {
>             "attachment_id": "5f73470a0e69dc",
>             "title": "This is the title",
>             "url": "https://url-to-image.com",
>             "subtitle": "This is the first subtitle",
>             "items": [
>                 {
>                     "type": "url",
>                     "url": "https://www.cognigy.com/",
>                     "title": "Visit Website"
>                 },
>                 {
>                     "type": "reply",
>                     "payload": "I want to select this one",
>                     "title": "Select"
>                 }
>             ]
>         },
>         "...": "..."
>     ]
>   }
> }
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.