Skip to content

Commit

Permalink
Begin adding documentation for readthedocs.org
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-weqe committed Feb 26, 2020
1 parent 4ca0821 commit 91bde83
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 1 deletion.
142 changes: 142 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

# python_webex_bot

A python3 library meant to help you create a cisco webex teams bot and take advantage of some of the features available to these bots.
Most of the python libraries setup for webex have been lacking in terms of connecting you to a webhook and this aims at solving that

## Installation and setup

The following are items this documentation assumes you already have installed:
- virtualenv
- python3
- <a href="https://ngrok.com/download">ngrok</a>

### Step 1: setup the virtual environment

to initialize the virtual environment, run the following command in your Command Line or Command Prompt
```
virtualenv venv
```

then we activate it:

<i>Windows</i>
```
venv\Scripts\activate
```

<i>Linux</i>
```
source venv/bin/activate
```

and there, you have your virtual environment setup and ready for action

### Step 2: install python_webex_bot

while still in your activated virtual environment, run the following command to install python_webex_bot via pip:

```
pip install python_webex_bot
```

then download <a href="https://ngrok.com/download">ngrok</a> which will be used in the concurrent steps

## Quickstart

Lets get a simple bot up, running and responsive on our local machine.

### Step 1: Create the bot on Cisco Webex

If you haven't already, <a href="https://teams.webex.com/signin">create your Webex account.</a>
Then head on to <a href="https://developer.webex.com/my-apps/new/bot">create your bot</a>

You should be provided with an <u>access token </u> for the bot.

Take this access token and place it in your environment variable as auth_token.

this can be done via your Command prompt or Command Line as:
```
export auth_token=my_auth_token
```

If you're on <i>Windows</i>, run the following on the command prompt:
```
set auth_token=my_auth_token
```

replace my_auth_token with your bots access token

<b>This is a crutial part of running your bot as the python_webex_bot library uses this to identify your bot</b>

If you still have some questions on environment variables, why we need them and how to use them, <a href="https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa">this</a> may be a good start

### Step 2: setup ngrok

in a different terminal from the one used in steps 1 and 2, navigate to the folder where you have the ngrok placed.

Then run the following command:
```
ngrok http 5000
```

This should produce an output similar to the one shown below:
```
Session Status online
Session Expires 7 hours, 59 minutes
Update update available (version 2.3.25, Ctrl-U to update)
Version 2.3.18
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://87a942a1.ngrok.io -> http://localhost:5000
Forwarding https://87a942a1.ngrok.io -> http://localhost:5000

Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
```

<i>Now you are ready for the quest</i>

### Step 3: create the python file and run it

Create a python file where you intend to run the bot. In my case, I will name my file `run.py`

copy and paste the following code:

```
from python_webex.v1.Bot import Bot
from python_webex import webhook

bot = Bot() # the program will automatically know the bot being referred to y the auth_token

# create a webhook to expose it to the internet
# rememer that url we got from step 2, this is where we use it. In my case it was http://87a942a1.ngrok.io.
# We will be creating a webhook that will be listening when messages are sent
bot.create_webhook(
name="quickstart_webhook", target_url="http://87a942a1.ngrok.io", resource="messages", event="created"
)

# we create a function that responds when someone says hi
# the room_id will automatically be filled with the webhook. Do not forget it
@bot.on_hears("hi)
def greet_back(room_id=None):
return bot.send_message(room_id=room_id, text="Hi, how are you doing?")

# We create a default response in case anyone types anything else that we have not set a response for
# this is done using * [ don't ask me what happend when someone sends '*' as the message, that's on my TODO]
@bot.on_hears("*")
def default_response(room_id=None):
return bot.send_message(room_id=room_id, text="Sorry, could not understand that")


# make the webhook know the bot to be listening for, and we are done
webhook.bot = bot

if __name__ == "__main__":
webhook.app.run(debug=True) # don't keep debug=True in production
```

Now, when we text our bot "hi", it will respond with "Hi, how are you doing?"

And when we text anything else, like "When can we meet up?" it will respond with "Sorry, I could not understand that"

142 changes: 142 additions & 0 deletions docs/python-webex-bot/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

# python_webex_bot

A python3 library meant to help you create a cisco webex teams bot and take advantage of some of the features available to these bots.
Most of the python libraries setup for webex have been lacking in terms of connecting you to a webhook and this aims at solving that

## Installation and setup

The following are items this documentation assumes you already have installed:
- virtualenv
- python3
- <a href="https://ngrok.com/download">ngrok</a>

### Step 1: setup the virtual environment

to initialize the virtual environment, run the following command in your Command Line or Command Prompt
```
virtualenv venv
```

then we activate it:

<i>Windows</i>
```
venv\Scripts\activate
```

<i>Linux</i>
```
source venv/bin/activate
```

and there, you have your virtual environment setup and ready for action

### Step 2: install python_webex_bot

while still in your activated virtual environment, run the following command to install python_webex_bot via pip:

```
pip install python_webex_bot
```

then download <a href="https://ngrok.com/download">ngrok</a> which will be used in the concurrent steps

## Quickstart

Lets get a simple bot up, running and responsive on our local machine.

### Step 1: Create the bot on Cisco Webex

If you haven't already, <a href="https://teams.webex.com/signin">create your Webex account.</a>
Then head on to <a href="https://developer.webex.com/my-apps/new/bot">create your bot</a>

You should be provided with an <u>access token </u> for the bot.

Take this access token and place it in your environment variable as auth_token.

this can be done via your Command prompt or Command Line as:
```
export auth_token=my_auth_token
```

If you're on <i>Windows</i>, run the following on the command prompt:
```
set auth_token=my_auth_token
```

replace my_auth_token with your bots access token

<b>This is a crutial part of running your bot as the python_webex_bot library uses this to identify your bot</b>

If you still have some questions on environment variables, why we need them and how to use them, <a href="https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa">this</a> may be a good start

### Step 2: setup ngrok

in a different terminal from the one used in steps 1 and 2, navigate to the folder where you have the ngrok placed.

Then run the following command:
```
ngrok http 5000
```

This should produce an output similar to the one shown below:
```
Session Status online
Session Expires 7 hours, 59 minutes
Update update available (version 2.3.25, Ctrl-U to update)
Version 2.3.18
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://87a942a1.ngrok.io -> http://localhost:5000
Forwarding https://87a942a1.ngrok.io -> http://localhost:5000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
```

<i>Now you are ready for the quest</i>

### Step 3: create the python file and run it

Create a python file where you intend to run the bot. In my case, I will name my file `run.py`

copy and paste the following code:

```
from python_webex.v1.Bot import Bot
from python_webex import webhook
bot = Bot() # the program will automatically know the bot being referred to y the auth_token
# create a webhook to expose it to the internet
# rememer that url we got from step 2, this is where we use it. In my case it was http://87a942a1.ngrok.io.
# We will be creating a webhook that will be listening when messages are sent
bot.create_webhook(
name="quickstart_webhook", target_url="http://87a942a1.ngrok.io", resource="messages", event="created"
)
# we create a function that responds when someone says hi
# the room_id will automatically be filled with the webhook. Do not forget it
@bot.on_hears("hi)
def greet_back(room_id=None):
return bot.send_message(room_id=room_id, text="Hi, how are you doing?")
# We create a default response in case anyone types anything else that we have not set a response for
# this is done using * [ don't ask me what happend when someone sends '*' as the message, that's on my TODO]
@bot.on_hears("*")
def default_response(room_id=None):
return bot.send_message(room_id=room_id, text="Sorry, could not understand that")
# make the webhook know the bot to be listening for, and we are done
webhook.bot = bot
if __name__ == "__main__":
webhook.app.run(debug=True) # don't keep debug=True in production
```

Now, when we text our bot "hi", it will respond with "Hi, how are you doing?"

And when we text anything else, like "When can we meet up?" it will respond with "Sorry, I could not understand that"

1 change: 1 addition & 0 deletions docs/python-webex-bot/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_name: Python-Webex-Bot
28 changes: 27 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,61 @@
alabaster==0.7.12
atomicwrites==1.3.0
attrs==19.1.0
Babel==2.8.0
backcall==0.1.0
bleach==3.1.1
certifi==2019.3.9
chardet==3.0.4
Click==7.0
colorama==0.4.1
commonmark==0.9.1
coverage==4.5.3
decorator==4.4.0
docutils==0.16
Flask==1.0.2
idna==2.8
imagesize==1.2.0
ipython==7.4.0
ipython-genutils==0.2.0
itsdangerous==1.1.0
jedi==0.13.3
Jinja2>=2.10.1
Jinja2==2.11.1
MarkupSafe==1.1.1
more-itertools==7.0.0
packaging==20.1
parso==0.3.4
pathlib2==2.3.5
pexpect==4.8.0
pickleshare==0.7.5
pkginfo==1.5.0.1
pluggy==0.9.0
prompt-toolkit==2.0.9
psycopg2==2.7.7
ptyprocess==0.6.0
py==1.8.0
Pygments==2.3.1
pyparsing==2.4.6
pytest==4.3.1
pytest-cov==2.6.1
pytz==2018.9
readme-renderer==24.0
recommonmark==0.6.0
requests==2.21.0
requests-toolbelt==0.9.1
six==1.12.0
snowballstemmer==2.0.0
Sphinx==2.4.3
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.2
sphinxcontrib-serializinghtml==1.1.3
tqdm==4.43.0
traitlets==4.3.2
twine==1.15.0
urllib3==1.24.1
virtualenv==16.4.3
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.15.3

0 comments on commit 91bde83

Please sign in to comment.