404
72 | 73 |Page not found
74 | 75 | 76 |├── __init__.py
├── python_webex
├── __init__.py
├── v1
│ ├── __init__.py
│ ├── People.py
│ ├── Bot.py
│ ├── Room.py
│ ├── Webhook.py
│ ├── Card.py
│ └── Message.py
└── webhook
│ ├── __init__.py
│ └── handlers.py
├── python_webex_bot
├── docs
├── site
│ ├── img
│ │ └── favicon.ico
│ ├── sitemap.xml.gz
│ ├── css
│ │ ├── fonts
│ │ │ ├── lato-bold.woff
│ │ │ ├── lato-bold.woff2
│ │ │ ├── lato-normal.woff
│ │ │ ├── lato-normal.woff2
│ │ │ ├── Roboto-Slab-Bold.woff
│ │ │ ├── Roboto-Slab-Bold.woff2
│ │ │ ├── fontawesome-webfont.eot
│ │ │ ├── fontawesome-webfont.ttf
│ │ │ ├── lato-bold-italic.woff
│ │ │ ├── lato-bold-italic.woff2
│ │ │ ├── lato-normal-italic.woff
│ │ │ ├── Roboto-Slab-Regular.woff
│ │ │ ├── Roboto-Slab-Regular.woff2
│ │ │ ├── fontawesome-webfont.woff
│ │ │ ├── fontawesome-webfont.woff2
│ │ │ └── lato-normal-italic.woff2
│ │ └── theme_extra.css
│ ├── js
│ │ ├── theme_extra.js
│ │ ├── html5shiv.min.js
│ │ └── theme.js
│ ├── sitemap.xml
│ ├── search
│ │ ├── main.js
│ │ ├── worker.js
│ │ └── search_index.json
│ ├── 404.html
│ ├── search.html
│ ├── cards
│ │ └── index.html
│ ├── rooms
│ │ └── index.html
│ ├── index.html
│ └── messages
│ │ └── index.html
├── mkdocs.yml
└── docs
│ ├── cards.md
│ ├── rooms.md
│ ├── index.md
│ └── messages.md
├── .gitignore
├── requirements.txt
├── setup.py
├── LICENSE
└── README.md
/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/python_webex/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/python_webex/v1/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/python_webex_bot:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | echo "hey there, this is my first pip package"
--------------------------------------------------------------------------------
/docs/site/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/img/favicon.ico
--------------------------------------------------------------------------------
/docs/site/sitemap.xml.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/sitemap.xml.gz
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-bold.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-bold.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-normal.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-normal.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-normal.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-normal.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/Roboto-Slab-Bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/Roboto-Slab-Bold.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/Roboto-Slab-Bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/Roboto-Slab-Bold.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/fontawesome-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/fontawesome-webfont.eot
--------------------------------------------------------------------------------
/docs/site/css/fonts/fontawesome-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/fontawesome-webfont.ttf
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-bold-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-bold-italic.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-bold-italic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-bold-italic.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-normal-italic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-normal-italic.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/Roboto-Slab-Regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/Roboto-Slab-Regular.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/Roboto-Slab-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/Roboto-Slab-Regular.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/fontawesome-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/fontawesome-webfont.woff
--------------------------------------------------------------------------------
/docs/site/css/fonts/fontawesome-webfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/fontawesome-webfont.woff2
--------------------------------------------------------------------------------
/docs/site/css/fonts/lato-normal-italic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Paul-weqe/python_webex_bot/HEAD/docs/site/css/fonts/lato-normal-italic.woff2
--------------------------------------------------------------------------------
/docs/mkdocs.yml:
--------------------------------------------------------------------------------
1 | site_name: Python-Webex-Bot
2 |
3 |
4 | nav:
5 | - Rooms: rooms.md
6 | - Messages: messages.md
7 | - Cards: cards.md
8 |
9 | theme:
10 | include_sidebar: true
11 | name: readthedocs
12 |
--------------------------------------------------------------------------------
/docs/site/js/theme_extra.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Assign 'docutils' class to tables so styling and
3 | * JavaScript behavior is applied.
4 | *
5 | * https://github.com/mkdocs/mkdocs/issues/2028
6 | */
7 |
8 | $('div.rst-content table').addClass('docutils');
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Procfile
2 | runtime.txt
3 | */__pycache__/*
4 | /python_webex_bot.egg-info/
5 | /__pycache__/*
6 | /venv/*
7 | .vscode
8 | .pytest_cache/
9 | */python_webex_bot.egg-info/*
10 | /dist/*
11 | /build/*
12 | test_script.py
13 | .gitignore
14 | *.pyc
15 | upgrade_version.sh
16 | .env
17 | test_script.sh
18 |
--------------------------------------------------------------------------------
/docs/site/sitemap.xml:
--------------------------------------------------------------------------------
1 |
2 | ' + escapeHtml(summary) +''+ escapeHtml(title) + '
' + noResultsText + '
'); 52 | } 53 | } 54 | 55 | function doSearch () { 56 | var query = document.getElementById('mkdocs-search-query').value; 57 | if (query.length > min_search_length) { 58 | if (!window.Worker) { 59 | displayResults(search(query)); 60 | } else { 61 | searchWorker.postMessage({query: query}); 62 | } 63 | } else { 64 | // Clear results for short queries 65 | displayResults([]); 66 | } 67 | } 68 | 69 | function initSearch () { 70 | var search_input = document.getElementById('mkdocs-search-query'); 71 | if (search_input) { 72 | search_input.addEventListener("keyup", doSearch); 73 | } 74 | var term = getSearchTermFromLocation(); 75 | if (term) { 76 | search_input.value = term; 77 | doSearch(); 78 | } 79 | } 80 | 81 | function onWorkerMessage (e) { 82 | if (e.data.allowSearch) { 83 | initSearch(); 84 | } else if (e.data.results) { 85 | var results = e.data.results; 86 | displayResults(results); 87 | } else if (e.data.config) { 88 | min_search_length = e.data.config.min_search_length-1; 89 | } 90 | } 91 | 92 | if (!window.Worker) { 93 | console.log('Web Worker API not supported'); 94 | // load index in main thread 95 | $.getScript(joinUrl(base_url, "search/worker.js")).done(function () { 96 | console.log('Loaded worker'); 97 | init(); 98 | window.postMessage = function (msg) { 99 | onWorkerMessage({data: msg}); 100 | }; 101 | }).fail(function (jqxhr, settings, exception) { 102 | console.error('Could not load worker.js'); 103 | }); 104 | } else { 105 | // Wrap search in a web worker 106 | var searchWorker = new Worker(joinUrl(base_url, "search/worker.js")); 107 | searchWorker.postMessage({init: true}); 108 | searchWorker.onmessage = onWorkerMessage; 109 | } 110 | -------------------------------------------------------------------------------- /docs/docs/cards.md: -------------------------------------------------------------------------------- 1 | 2 | # Cards 3 | 4 | ## Create & Send Blank Card 5 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 6 | 7 | Cards are meant to increase interactivity during the chat. They can be used, for example to send a form that the bot would like an end user to respond to. In this instance, we are sending a blank card to the user, which is pretty much useless. This can 8 | 9 | 10 | ```python 11 | from python.webex.v1.Card import Card 12 | from python.webex.v1.Bot import Bot 13 | 14 | bot = Bot() 15 | 16 | card = Card() 17 | 18 | bot.send_card(card=card, room_id="room-id") 19 | ``` 20 | 21 | ## Add text items on the card 22 | 23 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 24 | 25 | The card we just sent above is pretty much useless. If we are to send a card, the user needs to be able to interact with the card and the bot should be able to read whatever has been input on the user side. 26 | 27 | ```python 28 | from python_webex.v1.Card import Card 29 | from python_webex.v1.Bot import Bot 30 | 31 | bot = Bot() 32 | 33 | bot.create_webhook( 34 | name='attachment-response-2', target_url="[your-bot-url]/attachment-response", resource="attachmentActions", event="created" 35 | ) 36 | 37 | Card = Card() 38 | bot.send_card(card=card, room_id='room-id') 39 | ``` 40 | 41 | ## Create Card Webhook 42 | 43 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 44 | 45 | Here, we create a webhook for the card responses. For instance, if one fills a form that has been sent on a card, the response will be sent to the specific webhook. 46 | 47 | ```python 48 | from python_webex.v1.Card import Card 49 | from python_webex.v1.Bot import Bot 50 | 51 | bot = Bot() 52 | 53 | bot.create_webhook( 54 | name='attachment-response-2', target_url="[your-bot-url]/attachment-response", resource="attachmentActions", event="created" 55 | ) 56 | 57 | ``` 58 | 59 | Note: always make sure to setup this webhook to be whatever link you will be using and append /attachment-response to it. For example, if you are using 'https://abc.com', your value on target_url will be 'https://abc.com/attachment-response' 60 | 61 | ## Listen for response on card 62 | 63 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 64 | 65 | Now, what happens when the user has filled a card form and the response has been sent to the webhook, how do we get the information about the card that has been filled from our end? 66 | 67 | Here is how: 68 | 69 | ```python 70 | from python_webex.v1.Card import Card 71 | from python_webex.v1.Bot imporrt Bot 72 | from pprint import pprint 73 | from python_webex import webhook 74 | 75 | bot = Bot() 76 | card = Card() 77 | 78 | 79 | card.add_input_text( 80 | input_id="first-name-input", input_placeholder="First Name" 81 | ) 82 | 83 | card.add_input_text( 84 | input_id="last-name-input", input_placeholder="Last Name" 85 | ) 86 | 87 | card.add_submit_action_btn( 88 | title="Submit" 89 | ) 90 | 91 | message = bot.send_card(card=card, room_id="room-id") 92 | message_id = message.json()['id'] 93 | 94 | @bot.attachment_response(message_id=message_id) 95 | def respond_to_card(msg): 96 | pprint(msg) 97 | 98 | webhook.bot = bot 99 | 100 | if __name__ == "__main__": 101 | webhook.app.run(debug=True) 102 | 103 | ``` 104 | 105 | 106 | -------------------------------------------------------------------------------- /docs/docs/rooms.md: -------------------------------------------------------------------------------- 1 | # Rooms 2 | 3 | ## Get all rooms 4 | 5 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on here.* 6 | 7 | What we are aiming to do here is to get all the rooms that the bot is currently in. All from group rooms to individual rooms, we get all the details. Let us look at what we have to do: 8 | 9 | ``` 10 | from python_webex.v1.Bot import Bot 11 | 12 | bot = Bot() 13 | 14 | all_rooms_response = bot.get_all_rooms() 15 | 16 | all_rooms = all_rooms_response.json() 17 | 18 | print(all_rooms) 19 | 20 | ``` 21 | 22 | If everything works out fine you should see the following output: 23 | 24 | ``` 25 | { 26 | 'items': [ 27 | { 28 | 'title': 'room-title', 29 | 'ownerId': 'consumer', 30 | 'id': 'room-id', 31 | 'teamId': 'team-id', # this will show if it is a group room 32 | 'lastActivity': '2019-03-29T07:36:12.214Z', 33 | 'created': '2019-03-29T07:34:21.521Z', 34 | 'isLocked': False, 35 | 'creatorId': 'creator-id', 36 | 'type': 'group' 37 | } 38 | ] 39 | } 40 | ``` 41 | 42 | ## Get room details 43 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 44 | 45 | This gets the details of a specific room, we can use the output from here and get a single rooms ID. We will call the room ID room_id 46 | 47 | We will use this room_id to get the details of that specific room, here is how: 48 | 49 | ``` 50 | from python_webex.v1.Bot import Bot 51 | 52 | bot = Bot() 53 | 54 | room_id = 'someroomid' 55 | 56 | room_details_response = bot.get_room_details(room_id=room_id) 57 | 58 | room_details = room_details_response.json() 59 | 60 | print(room_details) 61 | 62 | ``` 63 | 64 | You should see an output similar to this: 65 | 66 | ``` 67 | { 68 | 'creatorId': 'creator-id', 69 | 'lastActivity': '2019-03-29T07:36:12.214Z', 70 | 'id': 'room-id', 71 | 'title': 'Discussion', 72 | 'created': '2019-03-29T07:34:21.521Z', 73 | 'type': 'group', 74 | 'ownerId': 'consumer', 75 | 'isLocked': False, 76 | 'teamId': 'team-id' # if the room is a team 77 | } 78 | 79 | ``` 80 | 81 | Use this information wisely. 82 | 83 | ## Create Room 84 | 85 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 86 | 87 | Some of the functionality for creating a room is still being worked on, bear with us. 88 | 89 | The following should work for creating a room: 90 | 91 | ``` 92 | from python_webex.v1.Bot import Bot 93 | 94 | bot = Bot() 95 | 96 | bot.create_room(title="Bot's room with best friend", team_id="team-id", room_type="something either 'direct' or 'group'") 97 | ``` 98 | 99 | ## Update Room Details 100 | 101 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 102 | 103 | Currently, we can only edit the title of a room. To do so, run the following script: 104 | 105 | ``` 106 | from python_webex.v1.Bot import Bot 107 | 108 | bot = Bot() 109 | 110 | room_id = 'room-id' 111 | 112 | bot.update_room_details(room_id=room_id, title='New Title') 113 | ``` 114 | 115 | ## Delete a room 116 | 117 | *Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.* 118 | 119 | Let us wreck some havock and delete a room. 120 | 121 | This can be done through: 122 | 123 | ``` 124 | from python_webex.v1.Bot import Bot 125 | 126 | bot = Bot() 127 | 128 | room_id = 'room-id' 129 | 130 | bot.delete_room(room_id=room_id) 131 | ``` 132 | -------------------------------------------------------------------------------- /docs/site/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |Page not found
74 | 75 | 76 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
91 |Cards are meant to increase interactivity during the chat. They can be used, for example to send a form that the bot would like an end user to respond to. In this instance, we are sending a blank card to the user, which is pretty much useless. This can
92 |from python.webex.v1.Card import Card
93 | from python.webex.v1.Bot import Bot
94 |
95 | bot = Bot()
96 |
97 | card = Card()
98 |
99 | bot.send_card(card=card, room_id="room-id")
100 |
101 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
103 |The card we just sent above is pretty much useless. If we are to send a card, the user needs to be able to interact with the card and the bot should be able to read whatever has been input on the user side.
104 |from python_webex.v1.Card import Card
105 | from python_webex.v1.Bot import Bot
106 |
107 | bot = Bot()
108 |
109 | bot.create_webhook(
110 | name='attachment-response-2', target_url="[your-bot-url]/attachment-response", resource="attachmentActions", event="created"
111 | )
112 |
113 | Card = Card()
114 | bot.send_card(card=card, room_id='room-id')
115 |
116 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
118 |Here, we create a webhook for the card responses. For instance, if one fills a form that has been sent on a card, the response will be sent to the specific webhook.
119 |from python_webex.v1.Card import Card
120 | from python_webex.v1.Bot import Bot
121 |
122 | bot = Bot()
123 |
124 | bot.create_webhook(
125 | name='attachment-response-2', target_url="[your-bot-url]/attachment-response", resource="attachmentActions", event="created"
126 | )
127 |
128 |
129 | Note: always make sure to setup this webhook to be whatever link you will be using and append /attachment-response to it. For example, if you are using 'https://abc.com', your value on target_url will be 'https://abc.com/attachment-response'
130 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
132 |Now, what happens when the user has filled a card form and the response has been sent to the webhook, how do we get the information about the card that has been filled from our end?
133 |Here is how:
134 |from python_webex.v1.Card import Card
135 | from python_webex.v1.Bot imporrt Bot
136 | from pprint import pprint
137 | from python_webex import webhook
138 |
139 | bot = Bot()
140 | card = Card()
141 |
142 |
143 | card.add_input_text(
144 | input_id="first-name-input", input_placeholder="First Name"
145 | )
146 |
147 | card.add_input_text(
148 | input_id="last-name-input", input_placeholder="Last Name"
149 | )
150 |
151 | card.add_submit_action_btn(
152 | title="Submit"
153 | )
154 |
155 | message = bot.send_card(card=card, room_id="room-id")
156 | message_id = message.json()['id']
157 |
158 | @bot.attachment_response(message_id=message_id)
159 | def respond_to_card(msg):
160 | pprint(msg)
161 |
162 | webhook.bot = bot
163 |
164 | if __name__ == "__main__":
165 | webhook.app.run(debug=True)
166 |
167 |
168 |
169 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on here.
93 |What we are aiming to do here is to get all the rooms that the bot is currently in. All from group rooms to individual rooms, we get all the details. Let us look at what we have to do:
94 |from python_webex.v1.Bot import Bot
95 |
96 | bot = Bot()
97 |
98 | all_rooms_response = bot.get_all_rooms()
99 |
100 | all_rooms = all_rooms_response.json()
101 |
102 | print(all_rooms)
103 |
104 |
105 | If everything works out fine you should see the following output:
106 |{
107 | 'items': [
108 | {
109 | 'title': 'room-title',
110 | 'ownerId': 'consumer',
111 | 'id': 'room-id',
112 | 'teamId': 'team-id', # this will show if it is a group room
113 | 'lastActivity': '2019-03-29T07:36:12.214Z',
114 | 'created': '2019-03-29T07:34:21.521Z',
115 | 'isLocked': False,
116 | 'creatorId': 'creator-id',
117 | 'type': 'group'
118 | }
119 | ]
120 | }
121 |
122 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
124 |This gets the details of a specific room, we can use the output from here and get a single rooms ID. We will call the room ID room_id
125 |We will use this room_id to get the details of that specific room, here is how:
126 |from python_webex.v1.Bot import Bot
127 |
128 | bot = Bot()
129 |
130 | room_id = 'someroomid'
131 |
132 | room_details_response = bot.get_room_details(room_id=room_id)
133 |
134 | room_details = room_details_response.json()
135 |
136 | print(room_details)
137 |
138 |
139 | You should see an output similar to this:
140 |{
141 | 'creatorId': 'creator-id',
142 | 'lastActivity': '2019-03-29T07:36:12.214Z',
143 | 'id': 'room-id',
144 | 'title': 'Discussion',
145 | 'created': '2019-03-29T07:34:21.521Z',
146 | 'type': 'group',
147 | 'ownerId': 'consumer',
148 | 'isLocked': False,
149 | 'teamId': 'team-id' # if the room is a team
150 | }
151 |
152 |
153 | Use this information wisely.
154 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
156 |Some of the functionality for creating a room is still being worked on, bear with us.
157 |The following should work for creating a room:
158 |from python_webex.v1.Bot import Bot
159 |
160 | bot = Bot()
161 |
162 | bot.create_room(title="Bot's room with best friend", team_id="team-id", room_type="something either 'direct' or 'group'")
163 |
164 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
166 |Currently, we can only edit the title of a room. To do so, run the following script:
167 |from python_webex.v1.Bot import Bot
168 |
169 | bot = Bot()
170 |
171 | room_id = 'room-id'
172 |
173 | bot.update_room_details(room_id=room_id, title='New Title')
174 |
175 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
177 |Let us wreck some havock and delete a room.
178 |This can be done through:
179 |from python_webex.v1.Bot import Bot
180 |
181 | bot = Bot()
182 |
183 | room_id = 'room-id'
184 |
185 | bot.delete_room(room_id=room_id)
186 |
187 |
188 | 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. 80 | 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
81 |The following are items this documentation assumes you already have installed: 83 | - virtualenv 84 | - python3 85 | - ngrok
86 |to initialize the virtual environment, run the following command in your Command Line or Command Prompt
88 |virtualenv venv
89 |
90 | then we activate it:
91 |Windows
92 |venv\Scripts\activate
93 |
94 | Linux
95 |source venv/bin/activate
96 |
97 | and there, you have your virtual environment setup and ready for action
98 |while still in your activated virtual environment, run the following command to install python_webex_bot via pip:
100 |pip install python_webex_bot
101 |
102 | then download ngrok which will be used in the concurrent steps
103 |Lets get a simple bot up, running and responsive on our local machine.
105 |If you haven't already, create your Webex account. 107 | Then head on to create your bot
108 |You should be provided with an access token for the bot.
109 |Take this access token and place it in your environment variable as auth_token.
110 |this can be done via your Command prompt or Command Line as:
111 |export auth_token=my_auth_token
112 |
113 | If you're on Windows, run the following on the command prompt:
114 |set auth_token=my_auth_token
115 |
116 | replace my_auth_token with your bots access token
117 |This is a crutial part of running your bot as the python_webex_bot library uses this to identify your bot
118 |If you still have some questions on environment variables, why we need them and how to use them, this may be a good start
119 |in a different terminal from the one used in steps 1 and 2, navigate to the folder where you have the ngrok placed.
121 |Then run the following command:
122 |ngrok http 5000
123 |
124 | This should produce an output similar to the one shown below:
125 |Session Status online
126 | Session Expires 7 hours, 59 minutes
127 | Update update available (version 2.3.25, Ctrl-U to update)
128 | Version 2.3.18
129 | Region United States (us)
130 | Web Interface http://127.0.0.1:4040
131 | Forwarding http://87a942a1.ngrok.io -> http://localhost:5000
132 | Forwarding https://87a942a1.ngrok.io -> http://localhost:5000
133 |
134 | Connections ttl opn rt1 rt5 p50 p90
135 | 0 0 0.00 0.00 0.00 0.00
136 |
137 | Now you are ready for the quest
138 |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:
141 |from python_webex.v1.Bot import Bot
142 | from python_webex import webhook
143 |
144 | bot = Bot() # the program will automatically know the bot being referred to y the auth_token
145 |
146 | # create a webhook to expose it to the internet
147 | # rememer that url we got from step 2, this is where we use it. In my case it was http://87a942a1.ngrok.io.
148 | # We will be creating a webhook that will be listening when messages are sent
149 | bot.create_webhook(
150 | name="quickstart_webhook", target_url="http://87a942a1.ngrok.io", resource="messages", event="created"
151 | )
152 |
153 | # we create a function that responds when someone says hi
154 | # the room_id will automatically be filled with the webhook. Do not forget it
155 | @bot.on_hears("hi")
156 | def greet_back(room_id=None):
157 | return bot.send_message(room_id=room_id, text="Hi, how are you doing?")
158 |
159 | # We create a default response in case anyone types anything else that we have not set a response for
160 | # this is done using * [ don't ask me what happend when someone sends '*' as the message, that's on my TODO]
161 | @bot.on_hears("*")
162 | def default_response(room_id=None):
163 | return bot.send_message(room_id=room_id, text="Sorry, could not understand that")
164 |
165 |
166 | # make the webhook know the bot to be listening for, and we are done
167 | webhook.bot = bot
168 |
169 | if __name__ == "__main__":
170 | webhook.app.run(debug=True) # don't keep debug=True in production
171 |
172 | Now, when we text our bot "hi", it will respond with "Hi, how are you doing?"
173 |And when we text anything else, like "When can we meet up?" it will respond with "Sorry, I could not understand that"
174 | 175 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
105 |Want to send a message from your bot to a specific room? No worries, here is how:
106 |from python_webex.v1.Bot import Bot
107 |
108 | bot = Bot()
109 |
110 | bot.send_message(to_person_email='person-email@gmail.com', text='This is some text')
111 | # or
112 | bot.send_message(room_id='someroomid', text='This is the text')
113 |
114 | # you can use either `room_id` will be given priority over `to_person_email` when both are used at the same time.
115 |
116 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
118 |To attach a files when sending a message, do this:
119 |from python_webex.v1.Bot import Bot
120 |
121 | bot = Bot()
122 |
123 | bot.send_message(room_id='room-id', text='I am sending a file', files=['https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-1029171697.jpg'])
124 |
125 | Note the files parameter may be a list, but only one field is allowed. Why Exactly? No Idea, ask Webex. And also you can only keep URI's on the files field and not a path to a file in a local directory.
126 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
128 |When we want to style our messages e.g using bold, italivs and so on, we can use markups. Have a look here to read more about how markups work.
129 |So, this is how we can send a markup:
130 |from python_webex.v1.Bot import Bot
131 |
132 | bot = Bot()
133 |
134 | markdown = """
135 | *This is italic*\n
136 | **This is bold**\n
137 | `This looks like code`
138 | """
139 | bot.send_markdown(
140 | to_person_email="some-email@gmail.com", markdown = markdown
141 | )
142 |
143 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
145 |This lists all the messages that have been received by the bot on a specific room.
146 |This is how we can get these details:
147 |from python_webex.v1.Bot import Bot
148 | from pprint import pprint
149 |
150 | bot = Bot()
151 |
152 | pprint(bot.get_messages(room_id="room-id").json())
153 |
154 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
156 |Gets a list of all messages sent in 1:1 rooms. This is basically a list of all the bot's DMs with a particular individual, done by providing the person's ID.
157 |This is how this is done:
158 |from python_webex.v1.Bot import Bot
159 | from pprint import pprint
160 |
161 | bot = Bot()
162 |
163 | pprint(bot.get_direct_messages(person_id="person-id").json())
164 |
165 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
167 |Gives you details about a specific message with ID message-id
168 |from python_webex.v1.Bot import Bot
169 | from pprint import pprint
170 |
171 | bot = Bot()
172 |
173 | pprin(bot.get_message_details(message_id="message-id").json())
174 |
175 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
177 |Deletes a specific message with ID message-id
178 |from python_webex.v1.Bot import Bot
179 | from pprint import pprint
180 |
181 | bot = Bot()
182 |
183 | bot.delete_message(message_id='message-id')
184 |
185 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples on this tutorial.
187 |If your bot need to be constantly listening for incoming messages, you need to set up a webhook. To set up a webhook, you need an address that is available via the public internet. You can use ngrok for this.
188 |If you have ngrok downloaded, type ./ngrok http 5000 if you are on Linux. Otherwise, type ngrok.exe http 5000 if you are on Windows. This will give you an output as such:
Session Expires 7 hours, 6 minutes
190 | Version 2.3.35
191 | Region United States (us)
192 | Web Interface http://127.0.0.1:4040
193 | Forwarding http://cff51342.ngrok.io -> http://localhost:5000
194 | Forwarding https://cff51342.ngrok.io -> http://localhost:5000
195 |
196 | Now, you can open up your text editor and type in the following:
197 |from python_webex.v1.Bot import Bot
198 | from python_webex import webhook
199 |
200 | bot = Bot()
201 | bot.create_webhook(
202 | name='some-normal-webhook', target_url='https://cff51342.ngrok.io', resource='messages', event='created'
203 | )
204 |
205 | webhook.bot = bot
206 |
207 | if __name__ == "__main__":
208 | webhook.app.run(debug=True)
209 |
210 | You willl now be constantly listening for any incoming message via the message that has been sent to the bot.
211 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples 213 | on this tutorial.
214 |When you receive a message, it normally comes with text. The following is how to set a default response whatever text is sent to the bot:
215 |from python_webex.v1.Bot import Bot
216 |
217 | bot = Bot()
218 |
219 | @bot.on_hears("*")
220 | def default_on_hears_function(room_id=None):
221 | bot.send_message(room_id=room_id, text="This is the default response for the message that has been sent")
222 |
223 | Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples 225 | on this tutorial.
226 |You want your bot to receive files? So do many other people.
227 |We need to have a way to handle how these files are received and handled. So here is how we set the default function for handling incoming files:
228 |from python_webex.v1.Bot import Bot
229 | from python_webex import webhook
230 |
231 | bot = Bot()
232 |
233 | @bot.set_default_file_response()
234 | def default_file_response(files, room_id=None):
235 | bot.send_message(room_id=room_id, text='this is the default response for an attached file')
236 |
237 | webhook.bot = bot
238 |
239 | if __name__ == "__main__":
240 | webhook.app.run(debug=True)
241 |
242 |
243 | If you need to attach anything in the response, refer to the previous tutorial about attaching files with messages
244 |Always remember that you need to have already set the value auth_token as your bot's Access token before you run this any of the other examples 246 | on this tutorial.
247 |What do you do when someone send you a file attached with a specific set of text, and you do know what you need your bot to do at this point:
248 |from python_webex.v1.Bot import Bot
249 | from python_webex import webhook
250 |
251 | bot = Bot()
252 |
253 | @bot.set_file_action("This is me")
254 | def custom_response(room_id=None, files=None):
255 | print(files)
256 | bot.send_message(room_id=room_id, text="You look amazing")
257 |
258 | webhook.bot = bot
259 |
260 | if __name__ == "__main__":
261 | webhook.app.run(debug=True)
262 |
263 |
264 | In def custom_response(room_id=None, files=None):, files represent a list of the files being sent to the bot.