rasa-vier-cvg


Namerasa-vier-cvg JSON
Version 1.3.5 PyPI version JSON
download
home_pagehttps://cognitivevoice.io
SummaryRasa-integration for the VIER Cognitive Voice Gateway
upload_time2024-03-12 17:28:13
maintainer
docs_urlNone
authorVIER GmbH
requires_python>=3.6
licenseMIT
keywords vier vier cognitive voice gateway sdk channel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Rasa and VIER Cognitive Voice Gateway

Rasa is the leading open-source conversational AI platform that enables both individual developers and large enterprises to build superior AI assistants and chatbots. Rasa provides the infrastructure and tools needed to build the outstanding tools and transform the way customers communicate with businesses. Rasa can be deeply customized down to levels not possible with other platforms due to the open sourced architecture and machine learning.

Rasa is used by millions of developers and small teams to program enterprise conversational AI applications.

Rasa is available in two editions: *Rasa Open Source* (free) and *Rasa Enterprise* (commercial). Both editions can be used to build voicebots with CVG.

[VIER Cognitive Voice Gateway (CVG)](https://cognitivevoice.io/docs) enables access to telephony, speech-to-text (STT), text-to-speech (TTS) and contact center integration for chatbots built with Rasa. I.e. CVG makes your chatbot to a voicebot handling phone calls.

To build voice bots using Rasa and CVG, you need an account in CVG and a Rasa installation.

### Installing Rasa

Rasa can be hosted anywhere: in the cloud, On-Prem or in any data center. Migrations between hosting solutions can be performed at any stage.

Many organizations developing chatbots and voicebots with Rasa start with Rasa Open Source On-Prem. An [installation guide](https://rasa.com/docs/rasa/installation/installing-rasa-open-source) is provided by Rasa. Rasa also provides a Playground that can be used to develop bots without requiring an On-Prem installation.

To install Rasa Enterprise, use the [installation guide](https://rasa.com/docs/rasa-enterprise/installation-and-setup/installation-guide) provided by Rasa.

### Installing VIER CVG Channel for Rasa

The Rasa integration with CVG is done with a new channel for Rasa provided in this repo.
It implements all the CVG APIs relevant for bots to provide CVGs full power to you as a Rasa developer.

The easiest way to install this package is through PyPI.

```
pip install rasa-vier-cvg
```

#### Docker

If you are using Rasa on Docker and you don't want to build a derived image, you can also download the [channel source](https://github.com/VIER-CognitiveVoice/rasa-vier-cvg/) and bind-mount the package into a `rasa/rasa`-base container with a volume definition like this:

```
./rasa_vier_cvg:/opt/venv/lib/python3.10/site-packages/rasa_vier_cvg
```

### Configure your Rasa Bot

Add the following content to `credentials.yml`:

```
rasa_vier_cvg.CVGInput:
  token: "CHOOSE_YOUR_TOKEN"
  blocking_endpoints: false
```
You can generate the token yourself. For example with any password generator.

This channel will be used for communication with CVG.
The Bot token is required so that Rasa can verify that CVG is communicating with your Rasa Bot.

The optional `blocking_endpoints` option allows to disable blocking CVG's request while processing the user message.
For compatibility reasons this option defaults to `true`, but we recommend setting it to `false`.

### Configuring CVG

If you do not yet have an account for CVG please contact us at [info@vier.ai](mailto:info@vier.ai).

![conversational-ai-rasa](https://user-images.githubusercontent.com/42033366/192627897-cc2ec42e-0bf4-4c91-bcf9-242a6077b609.PNG)

To configure the connection between your Rasa bot and [CVG](https://cognitivevoice.io) just select Rasa as the bot template, enter your Rasa URL (e.g. `https://rasa.example.org/webhooks/vier-cvg`) and your token, as set in credentials.yaml, in the CVG project settings.

![Configuring a Rasa project in CVG](https://github.com/VIER-CognitiveVoice/rasa-vier-cvg/blob/master/CVG-UI-configuring-a-rasa-project.png)

### Using the VIER CVG Channel in Rasa

#### Recieving Messages from CVG (Events)

Every message and intent sent by CVG will have a metadata-field called `cvg_body`. This field will always contain the JSON sent by CVG to the Rasa channel.
In the following sections, the term "metadata" will refer to this `cvg_body` field.

Normal spoken inputs from the user as well as DTMF inputs will be transmitted as text inputs to Rasa. All other CVG events will trigger specific intents as described below.
All messages and intents will have CVG's dialog ID as the `sender_id` field.

Text inputs follow [this specification](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/message). An example for the text input metadata would be:

```json
{
  "dialogId": "09e59647-5c77-4c02-a1c5-7fb2b47060f1",
  "projectContext": {
    "projectToken": "d30b1c38-b2fd-39c8-bec2-b268871338b0",
    "resellerToken": "ed4aff6d-c6f8-4ac9-ab67-d072ef45d9a0"
  },
  "timestamp": 1535546718115,
  "type": "SPEECH",
  "text": "Hello!",
  "confidence": 100,
  "vendor": "GOOGLE",
  "language": "en-US",
  "callback": "https://cognitivevoice.io/v1"
}
```

Voice and DTMF inputs can be differentiated using the `type` field, which would be `SPEECH` for voice and `DTMF` for DTMF tones.


Here is a list of the intents triggered by CVG for certain events:

* `cvg_session`: This intent is triggered once (after a new call has been established) before anything else to allow the bot to respond e.g. with a greeting. Metadata is defined by [this specification](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/session)
* `cvg_terminated`: This intent is triggered once the conversation has been terminated by the user. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/terminated).
* `cvg_inactivity`: This intent is triggered once the inactivity timeout has been triggered due to a lack of user input. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/inactivity).
* `cvg_recording`: This intent is triggered once the recording status changes. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/answer).
* `cvg_answer_number`, `cvg_answer_multiplechoice` and `cvg_answer_timeout`: These intents are triggered once a prompt (see next section) of type `Number` or `MultipleChoice` complete are timeout. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/answer).
* `cvg_outbound_success`: The success result of `forward` or `bridge` (see next section). It signals that the outgoing call has been successfully established. Metadata is specified by the response objects of the matching operations from the [Call API](/specs/?urls.primaryName=Call%20API#/call/forward).
* `cvg_outbound_failure`: The failure result of `forward` or `bridge` (see next section). It signals that the outgoing call could not be established and provides some details as to why. Metadata is specified by the response objects of the matching operations from the [Call API](/specs/?urls.primaryName=Call%20API#/call/forward).
  Depending on the exact reason (check out the `OutboundCallFailure` model in the
  [API specification](/specs/?urls.primaryName=Call%20API) for all possible reasons) there might not
  be a `ringStartTimestamp` and the `ringTime` could be zero.


#### Sending Messages to CVG (Commands)

The output channel for CVG supports `text_message`s and `custom_json`.

Text messages will be translated into [Say](/specs/?urls.primaryName=Call%20API#/call/say)-commands.

Every other command supported by the channel must be triggered by using custom JSON. The key for the custom JSON messages is an encoding of CVG's API endpoints and follows this schema:

```
cvg_<path with underscores instead of slashes>
```

So for example in order to use the [/call/play](/specs/?urls.primaryName=Call%20API#/call/play) endpoint you would use `cvg_call_play` as the key, for [/call/transcription/switch](/specs/?urls.primaryName=Call%20API#/call/switchTranscription) it would be `cvg_call_transcription_switch` and so on.

The JSON values will be used as-is as the request-body for the API call, so refer to the API documentations, most commonly the [Call API](/specs/?urls.primaryName=Call%20API) for specifics.
The only exception to this is, that the dialog ID (`sender_id`) which is automatically injected into the payloads as necessary.

Currently all operation documented in the [Call API](/specs/?urls.primaryName=Call%20API) as well as dialog_delete and dialog_data are implemented.

In case you want to call an API endpoint which is a bit more complex like `/call/forward` or something that is currently not implemented in this channel, you can use simply make the request manually using python.

#### Build a Rasa Bot (Example)

After setting up your Rasa Installation and configuring the CVG Project, let's create a simple Rasa Bot together.  
Create a new folder and generate the default bot:
```
rasa init
```
The bot is ready to be tested. Make sure you expose it in a way CVG can reach it, and configure the CVG channel.  

You can start the Rasa bot using `rasa run`. Make sure, you run `rasa train` after modifying the bot.

Please paste the following intents into your `domain.yml`. See below, on how the intent section should look like. They are explained [above](#communication), but don't worry about that yet.
```
intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge

  - cvg_outbound_success
  - cvg_outbound_failure
  - cvg_session
  - cvg_answer_multiplechoice # you can remove cvg_answer_*, if you don't use the /call/prompt feature.
  - cvg_answer_number
  - cvg_answer_timeout
  - cvg_message
  - cvg_inactivity
  - cvg_terminated
  - cvg_recording
```


To end the call / hang up after it said "Bye", you can modify the `utter_goodbye` message in the `domain.yml` like this:  
```
  utter_goodbye:
  - text: "Bye"
    custom:
      cvg_call_drop:
```

To forward the caller to an agent, you can modify `utter_iamabot` like this:
```
  utter_iamabot:
  - text: "I am a bot, powered by Rasa. But I will gladly forward you to a human."
    custom:
      cvg_call_forward:
        destinationNumber: "+4969907362380"
```


#### Use an action, to extract information from cvg

Please reference the Rasa documentation, on how to create and call a custom action.
This example will use the default Rasa action server, which you can start with `rasa run actions`

```
class ActionPrintCvgBody(Action):

    def name(self) -> Text:
        return "action_print_cvg_body" # The action name which you can use in your domain.yml

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        try:
          cvg_body = None
          for e in tracker.events[::-1]: # The loop will find the last message from the user
            if e["event"] == "user":
              cvg_body = e["metadata"]["cvg_body"]
              break
          print("Found cvg_body: ", cvg_body) # After we found the last message from the user and stored the CVG response body in cvg_body, we can print it
        except KeyError as e:
          print("Failed to read cvg_body: ", e) # The last user message did not contain the cvg_body. 
          # Note: The cvg_body is added by the CVG channel and won't be available if you use a different channel
        finally:
          return []
```


#### Now that we can send requests to CVG, let's receive them
You may already notice that the bot immediately says something after calling. That is because we haven't told Rasa yet how to handle the `cvg_session` intent.  
That intent is triggered when [/session](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client)#/bot/session) in the [Bot API](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client)) is called.

In your `stories.yml` replace the intent `greet` with `cvg_session`:
```diff
  steps:
-   - intent: greet
+   - or:
+    - intent: greet
+    - intent: cvg_session
```
Make sure to do that with all 3 stories and run `rasa train` before starting the Rasa bot.

To extract more information from the message inside an action, please read about [Events](#from-cvg-to-rasa-events) above.

The intents `cvg_outbound_success` and `cvg_outbound_failure` are relevant if you want to forward or bridge a call.  
You could do something like this in your `domain.yml`:
```
  utter_outbound_failure:
  - text: "Unfortunatly, the outbound call failed."
```
and in your `rules.yml`:
```
- rule: Handle outbound call failure
  steps:
  - intent: cvg_outbound_failure
  - action: utter_outbound_failure
```

This will inform the user about outbound call failures.
To handle the `cvg_outbound_success` intent, you can create an action, but we cannot say something to a call that has already been forwarded.

#### Prompt 
If you want to use the `/call/prompt` feature to prompt for a number, you can create the prompt and responses in your `domain.yml`:
```
  utter_prompt:
    - custom:
      cvg_call_prompt:
        text: Please provide 3 Numbers
        timeout: 10000
        type: 
          name: Number
          maxDigits: 3
          submitInputs:
            - DTMF_#

  utter_prompt_answer_number:
  - text: "You can access the result of the prompt inside a custom action."

  utter_prompt_timeout:
  - text: "You did not provide an answer, the prompt timed out"
```
For how the write such an action, see [below](#use-an-action-to-extract-information-from-cvg).

And add the following rules inside your `data/rules.yml`:
```
- rule: Handle prompt timeout
  steps:
  - intent: cvg_answer_timeout
  - action: utter_prompt_timeout

- rule: Handle prompt answer
  steps:
  - intent: cvg_answer_number
  - action: utter_prompt_answer_number
```


### Demo Voicebot built with Rasa and CVG

We provide a demo voicebot built with Rasa and CVG on [GitHub](https://github.com/VIER-CognitiveVoice/rasa-meter-reading-bot/). We also run this voicebot, so you can simply get a first impression. For more information, visit our [GitHub project](https://github.com/VIER-CognitiveVoice/rasa-meter-reading-bot/).

### Some details about the structure of this channel
- When CVG sends an event to Rasa, this channel will generate the intent (as specified [above](#from-rasa-to-cvg-commands))
  - The intent's metadata will contain the body sent by CVG as specified in the [Bot API](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client))
- When you utter a text message, or a [Custom Response](https://rasa.com/docs/rasa/responses/#custom-output-payloads), we pass the content of the payload to CVG after adding the `dialog_id`


            

Raw data

            {
    "_id": null,
    "home_page": "https://cognitivevoice.io",
    "name": "rasa-vier-cvg",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "VIER,VIER Cognitive Voice Gateway SDK,Channel",
    "author": "VIER GmbH",
    "author_email": "support@vier.ai",
    "download_url": "https://files.pythonhosted.org/packages/ad/fa/64ef3ce62714c960ae8b018d10c942d8fcd210fa1c4cda4f87cfce9010d5/rasa-vier-cvg-1.3.5.tar.gz",
    "platform": null,
    "description": "# Rasa and VIER Cognitive Voice Gateway\n\nRasa is the leading open-source conversational AI platform that enables both individual developers and large enterprises to build superior AI assistants and chatbots. Rasa provides the infrastructure and tools needed to build the outstanding tools and transform the way customers communicate with businesses. Rasa can be deeply customized down to levels not possible with other platforms due to the open sourced architecture and machine learning.\n\nRasa is used by millions of developers and small teams to program enterprise conversational AI applications.\n\nRasa is available in two editions: *Rasa Open Source* (free) and *Rasa Enterprise* (commercial). Both editions can be used to build voicebots with CVG.\n\n[VIER Cognitive Voice Gateway (CVG)](https://cognitivevoice.io/docs) enables access to telephony, speech-to-text (STT), text-to-speech (TTS) and contact center integration for chatbots built with Rasa. I.e. CVG makes your chatbot to a voicebot handling phone calls.\n\nTo build voice bots using Rasa and CVG, you need an account in CVG and a Rasa installation.\n\n### Installing Rasa\n\nRasa can be hosted anywhere: in the cloud, On-Prem or in any data center. Migrations between hosting solutions can be performed at any stage.\n\nMany organizations developing chatbots and voicebots with Rasa start with Rasa Open Source On-Prem. An [installation guide](https://rasa.com/docs/rasa/installation/installing-rasa-open-source) is provided by Rasa. Rasa also provides a Playground that can be used to develop bots without requiring an On-Prem installation.\n\nTo install Rasa Enterprise, use the [installation guide](https://rasa.com/docs/rasa-enterprise/installation-and-setup/installation-guide) provided by Rasa.\n\n### Installing VIER CVG Channel for Rasa\n\nThe Rasa integration with CVG is done with a new channel for Rasa provided in this repo.\nIt implements all the CVG APIs relevant for bots to provide CVGs full power to you as a Rasa developer.\n\nThe easiest way to install this package is through PyPI.\n\n```\npip install rasa-vier-cvg\n```\n\n#### Docker\n\nIf you are using Rasa on Docker and you don't want to build a derived image, you can also download the [channel source](https://github.com/VIER-CognitiveVoice/rasa-vier-cvg/) and bind-mount the package into a `rasa/rasa`-base container with a volume definition like this:\n\n```\n./rasa_vier_cvg:/opt/venv/lib/python3.10/site-packages/rasa_vier_cvg\n```\n\n### Configure your Rasa Bot\n\nAdd the following content to `credentials.yml`:\n\n```\nrasa_vier_cvg.CVGInput:\n  token: \"CHOOSE_YOUR_TOKEN\"\n  blocking_endpoints: false\n```\nYou can generate the token yourself. For example with any password generator.\n\nThis channel will be used for communication with CVG.\nThe Bot token is required so that Rasa can verify that CVG is communicating with your Rasa Bot.\n\nThe optional `blocking_endpoints` option allows to disable blocking CVG's request while processing the user message.\nFor compatibility reasons this option defaults to `true`, but we recommend setting it to `false`.\n\n### Configuring CVG\n\nIf you do not yet have an account for CVG please contact us at [info@vier.ai](mailto:info@vier.ai).\n\n![conversational-ai-rasa](https://user-images.githubusercontent.com/42033366/192627897-cc2ec42e-0bf4-4c91-bcf9-242a6077b609.PNG)\n\nTo configure the connection between your Rasa bot and [CVG](https://cognitivevoice.io) just select Rasa as the bot template, enter your Rasa URL (e.g. `https://rasa.example.org/webhooks/vier-cvg`) and your token, as set in credentials.yaml, in the CVG project settings.\n\n![Configuring a Rasa project in CVG](https://github.com/VIER-CognitiveVoice/rasa-vier-cvg/blob/master/CVG-UI-configuring-a-rasa-project.png)\n\n### Using the VIER CVG Channel in Rasa\n\n#### Recieving Messages from CVG (Events)\n\nEvery message and intent sent by CVG will have a metadata-field called `cvg_body`. This field will always contain the JSON sent by CVG to the Rasa channel.\nIn the following sections, the term \"metadata\" will refer to this `cvg_body` field.\n\nNormal spoken inputs from the user as well as DTMF inputs will be transmitted as text inputs to Rasa. All other CVG events will trigger specific intents as described below.\nAll messages and intents will have CVG's dialog ID as the `sender_id` field.\n\nText inputs follow [this specification](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/message). An example for the text input metadata would be:\n\n```json\n{\n  \"dialogId\": \"09e59647-5c77-4c02-a1c5-7fb2b47060f1\",\n  \"projectContext\": {\n    \"projectToken\": \"d30b1c38-b2fd-39c8-bec2-b268871338b0\",\n    \"resellerToken\": \"ed4aff6d-c6f8-4ac9-ab67-d072ef45d9a0\"\n  },\n  \"timestamp\": 1535546718115,\n  \"type\": \"SPEECH\",\n  \"text\": \"Hello!\",\n  \"confidence\": 100,\n  \"vendor\": \"GOOGLE\",\n  \"language\": \"en-US\",\n  \"callback\": \"https://cognitivevoice.io/v1\"\n}\n```\n\nVoice and DTMF inputs can be differentiated using the `type` field, which would be `SPEECH` for voice and `DTMF` for DTMF tones.\n\n\nHere is a list of the intents triggered by CVG for certain events:\n\n* `cvg_session`: This intent is triggered once (after a new call has been established) before anything else to allow the bot to respond e.g. with a greeting. Metadata is defined by [this specification](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/session)\n* `cvg_terminated`: This intent is triggered once the conversation has been terminated by the user. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/terminated).\n* `cvg_inactivity`: This intent is triggered once the inactivity timeout has been triggered due to a lack of user input. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/inactivity).\n* `cvg_recording`: This intent is triggered once the recording status changes. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/answer).\n* `cvg_answer_number`, `cvg_answer_multiplechoice` and `cvg_answer_timeout`: These intents are triggered once a prompt (see next section) of type `Number` or `MultipleChoice` complete are timeout. Metadata is specified [here](/specs/?urls.primaryName=Bot%20API%20%28Client%29#/bot/answer).\n* `cvg_outbound_success`: The success result of `forward` or `bridge` (see next section). It signals that the outgoing call has been successfully established. Metadata is specified by the response objects of the matching operations from the [Call API](/specs/?urls.primaryName=Call%20API#/call/forward).\n* `cvg_outbound_failure`: The failure result of `forward` or `bridge` (see next section). It signals that the outgoing call could not be established and provides some details as to why. Metadata is specified by the response objects of the matching operations from the [Call API](/specs/?urls.primaryName=Call%20API#/call/forward).\n  Depending on the exact reason (check out the `OutboundCallFailure` model in the\n  [API specification](/specs/?urls.primaryName=Call%20API) for all possible reasons) there might not\n  be a `ringStartTimestamp` and the `ringTime` could be zero.\n\n\n#### Sending Messages to CVG (Commands)\n\nThe output channel for CVG supports `text_message`s and `custom_json`.\n\nText messages will be translated into [Say](/specs/?urls.primaryName=Call%20API#/call/say)-commands.\n\nEvery other command supported by the channel must be triggered by using custom JSON. The key for the custom JSON messages is an encoding of CVG's API endpoints and follows this schema:\n\n```\ncvg_<path with underscores instead of slashes>\n```\n\nSo for example in order to use the [/call/play](/specs/?urls.primaryName=Call%20API#/call/play) endpoint you would use `cvg_call_play` as the key, for [/call/transcription/switch](/specs/?urls.primaryName=Call%20API#/call/switchTranscription) it would be `cvg_call_transcription_switch` and so on.\n\nThe JSON values will be used as-is as the request-body for the API call, so refer to the API documentations, most commonly the [Call API](/specs/?urls.primaryName=Call%20API) for specifics.\nThe only exception to this is, that the dialog ID (`sender_id`) which is automatically injected into the payloads as necessary.\n\nCurrently all operation documented in the [Call API](/specs/?urls.primaryName=Call%20API) as well as dialog_delete and dialog_data are implemented.\n\nIn case you want to call an API endpoint which is a bit more complex like `/call/forward` or something that is currently not implemented in this channel, you can use simply make the request manually using python.\n\n#### Build a Rasa Bot (Example)\n\nAfter setting up your Rasa Installation and configuring the CVG Project, let's create a simple Rasa Bot together.  \nCreate a new folder and generate the default bot:\n```\nrasa init\n```\nThe bot is ready to be tested. Make sure you expose it in a way CVG can reach it, and configure the CVG channel.  \n\nYou can start the Rasa bot using `rasa run`. Make sure, you run `rasa train` after modifying the bot.\n\nPlease paste the following intents into your `domain.yml`. See below, on how the intent section should look like. They are explained [above](#communication), but don't worry about that yet.\n```\nintents:\n  - greet\n  - goodbye\n  - affirm\n  - deny\n  - mood_great\n  - mood_unhappy\n  - bot_challenge\n\n  - cvg_outbound_success\n  - cvg_outbound_failure\n  - cvg_session\n  - cvg_answer_multiplechoice # you can remove cvg_answer_*, if you don't use the /call/prompt feature.\n  - cvg_answer_number\n  - cvg_answer_timeout\n  - cvg_message\n  - cvg_inactivity\n  - cvg_terminated\n  - cvg_recording\n```\n\n\nTo end the call / hang up after it said \"Bye\", you can modify the `utter_goodbye` message in the `domain.yml` like this:  \n```\n  utter_goodbye:\n  - text: \"Bye\"\n    custom:\n      cvg_call_drop:\n```\n\nTo forward the caller to an agent, you can modify `utter_iamabot` like this:\n```\n  utter_iamabot:\n  - text: \"I am a bot, powered by Rasa. But I will gladly forward you to a human.\"\n    custom:\n      cvg_call_forward:\n        destinationNumber: \"+4969907362380\"\n```\n\n\n#### Use an action, to extract information from cvg\n\nPlease reference the Rasa documentation, on how to create and call a custom action.\nThis example will use the default Rasa action server, which you can start with `rasa run actions`\n\n```\nclass ActionPrintCvgBody(Action):\n\n    def name(self) -> Text:\n        return \"action_print_cvg_body\" # The action name which you can use in your domain.yml\n\n    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:\n        try:\n          cvg_body = None\n          for e in tracker.events[::-1]: # The loop will find the last message from the user\n            if e[\"event\"] == \"user\":\n              cvg_body = e[\"metadata\"][\"cvg_body\"]\n              break\n          print(\"Found cvg_body: \", cvg_body) # After we found the last message from the user and stored the CVG response body in cvg_body, we can print it\n        except KeyError as e:\n          print(\"Failed to read cvg_body: \", e) # The last user message did not contain the cvg_body. \n          # Note: The cvg_body is added by the CVG channel and won't be available if you use a different channel\n        finally:\n          return []\n```\n\n\n#### Now that we can send requests to CVG, let's receive them\nYou may already notice that the bot immediately says something after calling. That is because we haven't told Rasa yet how to handle the `cvg_session` intent.  \nThat intent is triggered when [/session](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client)#/bot/session) in the [Bot API](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client)) is called.\n\nIn your `stories.yml` replace the intent `greet` with `cvg_session`:\n```diff\n  steps:\n-   - intent: greet\n+   - or:\n+    - intent: greet\n+    - intent: cvg_session\n```\nMake sure to do that with all 3 stories and run `rasa train` before starting the Rasa bot.\n\nTo extract more information from the message inside an action, please read about [Events](#from-cvg-to-rasa-events) above.\n\nThe intents `cvg_outbound_success` and `cvg_outbound_failure` are relevant if you want to forward or bridge a call.  \nYou could do something like this in your `domain.yml`:\n```\n  utter_outbound_failure:\n  - text: \"Unfortunatly, the outbound call failed.\"\n```\nand in your `rules.yml`:\n```\n- rule: Handle outbound call failure\n  steps:\n  - intent: cvg_outbound_failure\n  - action: utter_outbound_failure\n```\n\nThis will inform the user about outbound call failures.\nTo handle the `cvg_outbound_success` intent, you can create an action, but we cannot say something to a call that has already been forwarded.\n\n#### Prompt \nIf you want to use the `/call/prompt` feature to prompt for a number, you can create the prompt and responses in your `domain.yml`:\n```\n  utter_prompt:\n    - custom:\n      cvg_call_prompt:\n        text: Please provide 3 Numbers\n        timeout: 10000\n        type: \n          name: Number\n          maxDigits: 3\n          submitInputs:\n            - DTMF_#\n\n  utter_prompt_answer_number:\n  - text: \"You can access the result of the prompt inside a custom action.\"\n\n  utter_prompt_timeout:\n  - text: \"You did not provide an answer, the prompt timed out\"\n```\nFor how the write such an action, see [below](#use-an-action-to-extract-information-from-cvg).\n\nAnd add the following rules inside your `data/rules.yml`:\n```\n- rule: Handle prompt timeout\n  steps:\n  - intent: cvg_answer_timeout\n  - action: utter_prompt_timeout\n\n- rule: Handle prompt answer\n  steps:\n  - intent: cvg_answer_number\n  - action: utter_prompt_answer_number\n```\n\n\n### Demo Voicebot built with Rasa and CVG\n\nWe provide a demo voicebot built with Rasa and CVG on [GitHub](https://github.com/VIER-CognitiveVoice/rasa-meter-reading-bot/). We also run this voicebot, so you can simply get a first impression. For more information, visit our [GitHub project](https://github.com/VIER-CognitiveVoice/rasa-meter-reading-bot/).\n\n### Some details about the structure of this channel\n- When CVG sends an event to Rasa, this channel will generate the intent (as specified [above](#from-rasa-to-cvg-commands))\n  - The intent's metadata will contain the body sent by CVG as specified in the [Bot API](https://stage.cognitivevoice.io/specs/?urls.primaryName=Bot%20API%20(Client))\n- When you utter a text message, or a [Custom Response](https://rasa.com/docs/rasa/responses/#custom-output-payloads), we pass the content of the payload to CVG after adding the `dialog_id`\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Rasa-integration for the VIER Cognitive Voice Gateway",
    "version": "1.3.5",
    "project_urls": {
        "Bug Reports": "https://github.com/VIER-CognitiveVoice/rasa-vier-cvg/issues",
        "Homepage": "https://cognitivevoice.io",
        "Source": "https://github.com/VIER-CognitiveVoice/rasa-vier-cvg"
    },
    "split_keywords": [
        "vier",
        "vier cognitive voice gateway sdk",
        "channel"
    ],
    "urls": [
        {
            "comment_text": "Built from tag 1.3.5",
            "digests": {
                "blake2b_256": "bf518ec5d68480f05af3c04532fc176a71cea6d6ee270e75000efb7bc90a3034",
                "md5": "49f58a3cf03341230f238a7bbde8b83f",
                "sha256": "29cbe6cc9e9f3621916e148d58a187ed394fb5730f9e137acb7af8d57d31fc6c"
            },
            "downloads": -1,
            "filename": "rasa_vier_cvg-1.3.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49f58a3cf03341230f238a7bbde8b83f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 12590,
            "upload_time": "2024-03-12T17:28:12",
            "upload_time_iso_8601": "2024-03-12T17:28:12.026155Z",
            "url": "https://files.pythonhosted.org/packages/bf/51/8ec5d68480f05af3c04532fc176a71cea6d6ee270e75000efb7bc90a3034/rasa_vier_cvg-1.3.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "Built from tag 1.3.5",
            "digests": {
                "blake2b_256": "adfa64ef3ce62714c960ae8b018d10c942d8fcd210fa1c4cda4f87cfce9010d5",
                "md5": "269bf50349be325968c840061944631c",
                "sha256": "c8750a2d5cd6180c8ab8fd0d4e386e8fb2afd1708a6686ade9226ef5fabfdb0f"
            },
            "downloads": -1,
            "filename": "rasa-vier-cvg-1.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "269bf50349be325968c840061944631c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 17444,
            "upload_time": "2024-03-12T17:28:13",
            "upload_time_iso_8601": "2024-03-12T17:28:13.267905Z",
            "url": "https://files.pythonhosted.org/packages/ad/fa/64ef3ce62714c960ae8b018d10c942d8fcd210fa1c4cda4f87cfce9010d5/rasa-vier-cvg-1.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 17:28:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "VIER-CognitiveVoice",
    "github_project": "rasa-vier-cvg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "rasa-vier-cvg"
}
        
Elapsed time: 0.20040s