servisbotsdk 0.1.1
ServisBOT SDK for Data Science
Requires Python: >=3.7,<4.0

# py-sb-sdk

## Prerequisites 
* Python 3.7

## SbAuth
The SbAuth class is used to encapsulate the signing of requests for specific resources. 
You must export your AWS credentials to allow the SDK to sign requests:
```
export AWS_ACCESS_KEY_ID="key_id"
export AWS_SECRET_ACCESS_KEY="access_key"
export AWS_SESSION_TOKEN="token"
```

SbAuth will attempt to configure the AWS Region by looking checking the following values in this order:
* `aws_region` passed to the constructor of SbAuth through the named argument `aws_region`.
* `AWS_DEFAULT_REGION` in your environment variables 
* `AWS_REGION` in your environment variables
* Checks to see if boto3 has found a region by checking the local aws config file, or possibly through an AWS client that is being used during the boto session.
If SbAuth can not set an AWS Region an Exception is thrown.

To initialize an SbAuth object you can do the following:
```python
from servisbotsdk import SbAuth
org = "flowit"
sb_auth = SbAuth(org, broca_url="https://broca.testdomain.test")
```
If you need to override the AWS region you can pass it as an argument to the constructor
```python
from servisbotsdk import SbAuth
org = "flowit"
sb_auth = SbAuth(org, broca_url="https://broca.testdomain.test", aws_region="eu-west-1")
```

## Intent
### Describe
#### Code Snippet
```python
from servisbotsdk import SbAuth, Intent
org = "flowit"
sb_auth = SbAuth(
    org,
    broca_url="https://broca.testdomain.test",
)
intent = Intent(sb_auth)
describe_resp = intent.describe("bot-name", "alias")
```
#### Response
```python
{
  'alias': 'alias',
  'displayName': 'pricing',
  'bot': 'bot-name',
  'version': '$LATEST',
  'utterances': [{
    'text': 'What is the price of a large coffee',
    'enabled': True
  }],
  'fulfilment': {
    'actions': '[]'
  },
  'detection': {
    'actions': '[]'
  },
  'scope': None,
  'slots': []
}
```
### List
#### Code Snippet
```python
from servisbotsdk import SbAuth, Intent
org = "flowit"
sb_auth = SbAuth(
    org,
    broca_url="https://broca.testdomain.test",
)
intent = Intent(sb_auth)

resp = intent.list("DeanBIDF", {"limit": 1})

second_page = intent.list("bot-name", {"nextToken": resp["nextToken"], "limit": 1})
```
#### Response
```python
{
  'intents': [{
    'alias': 'sizing',
    'displayName': 'sizing',
    'bot': 'botname',
    'version': '$LATEST',
    'utterances': [{
      'text': 'how much caffeine is in a large coffee',
      'enabled': True
    }, {
      'text': 'why is a flat white so small',
      'enabled': True
    }, {
      'text': 'why are medium coffees not large coffees',
      'enabled': True
    }],
    'fulfilment': {
      'actions': '[{"type":"message","value":"some value"}]'
    },
    'detection': {
      'actions': '[]'
    },
    'scope': None
  }],
  'nextToken': 'some-token'
}
```
## Pagination
Some resources allow you to iterate through the resource using a paginator. The arguments passed to the paginator will vary depending on the resource. An example of pagination be found below:
```python
from servisbotsdk import SbAuth, Intent
org = "flowit"
sb_auth = SbAuth(
    org,
    broca_url="https://broca.testdomain.test",
)
intent = Intent(sb_auth)
for intents in intent.paginator("DeanBIDF", {"limit": 1}):
    for intent in intents:
        print(intent)
```