Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions endpoint/webchat/microsoftSentimentAnalysis/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Description
This transformer example shows how to integrate real time sentiment analysis to every user input using [Microsoft Cognitive Services](https://azure.microsoft.com/en-us/products/cognitive-services/text-analytics)

# Usage
To use this transformer you will need to create a key and find out the region of your Azure Cognitive Services enpoint. Information regarding this can be found [in this document from Microsoft](https://learn.microsoft.com/en-us/rest/api/cognitiveservices-textanalytics/).


After creating the Microsoft Cognitive Services Endpoint, the contents of the ``transformer.ts`` file have to be copied into the Transformer Function of the webchat Endpoint. Afterwards, the ``Input Transformer`` has to be ``enabled``.

You will need to replace with beginning of the ``cognitiveServiceUrl`` with the region of your Cognitive Services endpoint (for example "germanywestcentral", "uswest" etc.).
The ``cognitiveServiceKey`` will need to be replaced with the key from your Cognitive Services Endpoint.

The sentiment of each user statement will then be added to the data object of the user input.

<img src="./docs/MicrosoftSentimentInDataObject.png" width="30%">
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions endpoint/webchat/microsoftSentimentAnalysis/transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const cognitiveServiceUrl = "https://germanywestcentral.api.cognitive.microsoft.com/text/analytics/v3.0/sentiment"
const cognitiveServiceKey = ""
//@ts-ignore

createSocketTransformer({

/**
* This transformer is executed when receiving a message
* from the user, before executing the Flow.
*
* @param payload The payload object containing userId, sessionId, text etc.
* @param endpoint The configuration object for the used Endpoint.
*
* @returns A valid userId, sessionId, as well as text and/or data,
* which has been extracted from the payload.
*/

handleInput: async ({ payload, endpoint }) => {
//@ts-ignore
const sessionStorage = await getSessionStorage(payload.userId, payload.sessionId);
sessionStorage.id++

if (payload?.data?._cognigy?.event?.type === "user-connected") {
return null
}

let text = payload.text
let data = {}

console.info(payload)
//@ts-ignore
const result = await httpRequest({
url: cognitiveServiceUrl,
headers: {
"Ocp-Apim-Subscription-Key": cognitiveServiceKey,
"Content-Type": "application/json"
},
method: "POST",
body: {
"documents": [
{
"id": sessionStorage.id,
"text": text
}
]

},
json: true
});

console.log(result)
if (payload.data) {
data["payload"]
}
data["sentiment"] = result


return {
userId: payload.userId,
sessionId: payload.sessionId,
text: text,
data: data
};
}
});
131 changes: 131 additions & 0 deletions endpoint/webhook/instagram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Instagram
This Endpoint Transformer provides a native integration with Instagram.

It allows Cognigy to both answer direct messages as well as respond to comments on posts.

Please read this document for detailed information on the what needs to be considered when creating an Instagram endpoint.
https://developers.facebook.com/docs/messenger-platform/instagram/

After completing an agent with this endpoint please look at this document for information in regards to what needs to be considered to have the bot be approved for publication by Instagram/Meta:
https://developers.facebook.com/docs/messenger-platform/instagram/app-review/apps-for-your-own-business


## Message Types

- Text
- Text with Quick Replies
- Image
- Video
- Audio
- Galleries
- Reactions
- Comment replies

## How to Setup

1. In order to create the required **Facebook Developer** Account and connect it to your instagram page, please read the official documentation here: https://developers.facebook.com/docs/messenger-platform/instagram/get-started <img src="./docs/facebookForDevelopers.png" width="800" />
2. Insert the Webhook URL from the Cognigy.AI Endpoint as "Webhook Callback-URL"
3. Define a `VERIFY_TOKEN` in the transformer.ts and insert the same value in the "Verification Token" field.
4. Find your the page ID for your Instagram webpage and add it to the `PAGE_ID` field.
5. Create an access token in the developer portal and add it to the `ACCESS_TOKEN` field

## Messages from user
The user is able to send multiple types of messages including images, audio and video. What type of message you receive from the user can be seen in the `input.data.type` field of the `input` object.

For most media file types a download link for the media can be found in the `input.entry[0].messaging[0].message.attachments[0].payload` field.

## Message Types

### Text

The **Text** type is the default of the say node.

### Media

<img src="./docs/InstagramImage.png" width="50%">

<img src="./docs/InstagramAudio.png" width="50%">

You can send media such as **images**, **video** or **audio files**.

### Gallery

<img src="./docs/InstagramGallery.png" width="50%">

The **Gallery** type of the say node can also be used. Images must be defined for each item.

### Quick Reply

<img src="./docs/InstagramQuickReplies.png" width="50%">

Use the **Text with Quick Replies** to add quick type messages to the chat. The quick replies can either have a payload or a be a URL for external webpages.

### Respond to Message Reactions

<img src="./docs/InstagramReactionReply.png" width="50%">

You can also see if the user reacted to your message and respond accordingly.
Reactions can be recognized by the `reaction` value in the `input.data.type` field.

### Posts/Data messages

<img src="./docs/InstagramPost.png" width="50%">

You can also send other types of [media supported by Instagram](https://developers.facebook.com/docs/messenger-platform/instagram/features/send-message) by sending it as a data message, for example if you want to share an Instagram post in the replies. You just need to add a JSON object in the **Data** field of your output node. In this example we used data with the following JSON format.

```json
{
"type": "data",
"message": {
"attachment": {
"type": "MEDIA_SHARE",
"payload": {
"id": "123456789123456789"
}
}
}
}
```

**IMPORTANT** you must add the `{"type": "data"}` key value pair to the data unless it won't be recognized.

### Reactions

<img src="./docs/InstagramBotReaction.png" width="50%">

It is also possible to react to a user's message by giving it a "like". To do this you could add the following to the data field of your say node:

```json
{
"type": "reaction",
"sender_action": "react",
"payload": {
"message_id": "{{input.data.entry[0].messaging[0].message.mid}}",
"reaction": "love"
}
}
```

To unreact to a message you can also add the following to the data:

```json
{
"type": "reaction",
"sender_action": "unreact",
"payload": {
"message_id": "{{input.data.entry[0].messaging[0].message.mid}}"
}
}
```

The field `input.data.entry[0].messaging[0].message.mid` is where you can find the value with the message ID for the last message send by the user.

**IMPORTANT** you must add the `{"type": "reaction"}` key value pair to the data unless it won't be recognized.

### Comment responses

<img src="./docs/InstagramComments.png" width="50%">

You can also respond to comments if you have them set up in your [Instagram Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/getting-started/webhooks-for-instagram).

Only say nodes with simple text are currently supported in comments.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading