From 982f14dd87de2ca89e34a3d82104ae508ebb33d8 Mon Sep 17 00:00:00 2001 From: "Sakthivel Ramasamy (sakthram)" Date: Mon, 26 Aug 2024 22:03:01 +0530 Subject: [PATCH 1/2] Migrate from "webexteamssdk" library to "webexpythonsdk" library Migration from "webexteamssdk" library to "webexpythonsdk" library. All instances of package name "webexteamssdk" is replaced with "webexpythonsdk". All instances of primary API object "WebexTeamsAPI" is replaced with "WebexAPI". All instances of access token environment variable "WEBEX_TEAMS_ACCESS_TOKEN" is replaced with "WEBEX_ACCESS_TOKEN". Changes are inline with "https://webexcommunity.github.io/WebexPythonSDK/user/migrate.html" and tested with my local Webex bot (which resulted in no errors). Only thing is all instances of "webexteamssdk" references in local Webex bot had to be replaced with "webexpythonsdk". --- README.md | 12 ++++++------ example.py | 2 +- requirements_dev.txt | 2 +- setup.py | 2 +- webex_bot/commands/echo.py | 4 ++-- webex_bot/commands/help.py | 4 ++-- webex_bot/models/command.py | 4 ++-- webex_bot/models/response.py | 2 +- webex_bot/webex_bot.py | 6 +++--- webex_bot/websockets/webex_websocket_client.py | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index cf63be2..a6a0462 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ inside a LAN. This package instead uses a websocket to receive messages from the * Allows for single or multi-post responses. This is useful if you want to reply with a lot of data, but it won't all fit in a single response. * Restrict bot to certain users or domains. -* Uses the [webexteamssdk][2] package to send back replies from the bot. +* Uses the [webexpythonsdk][2] package to send back replies from the bot. ## 🚀 Getting started @@ -48,7 +48,7 @@ If you need optional proxy support, use this command instead: 2. On the Webex Developer portal, create a new [bot token][3] and expose it as an environment variable. ```sh -export WEBEX_TEAMS_ACCESS_TOKEN= +export WEBEX_ACCESS_TOKEN= ``` 3. Run your script: @@ -71,7 +71,7 @@ proxies = { } # Create a Bot Object -bot = WebexBot(teams_bot_token=os.getenv("WEBEX_TEAMS_ACCESS_TOKEN"), +bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN"), approved_rooms=['06586d8d-6aad-4201-9a69-0bf9eeb5766e'], bot_name="My Teams Ops Bot", include_demo_commands=True, @@ -89,9 +89,9 @@ where EchoCommand is defined as: ```python import logging -from webexteamssdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ +from webexpythonsdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ Text, Image, HorizontalAlignment -from webexteamssdk.models.cards.actions import Submit +from webexpythonsdk.models.cards.actions import Submit from webex_bot.formatting import quote_info from webex_bot.models.command import Command @@ -370,7 +370,7 @@ and off you go! [1]: https://github.com/aaugustin/websockets -[2]: https://github.com/CiscoDevNet/webexteamssdk +[2]: https://github.com/WebexCommunity/WebexPythonSDK [3]: https://developer.webex.com/docs/bots diff --git a/example.py b/example.py index 075b00d..bc842ea 100644 --- a/example.py +++ b/example.py @@ -11,7 +11,7 @@ } # Create a Bot Object -bot = WebexBot(teams_bot_token=os.getenv("WEBEX_TEAMS_ACCESS_TOKEN"), +bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN"), approved_rooms=['06586d8d-6aad-4201-9a69-0bf9eeb5766e'], bot_name="My Teams Ops Bot", include_demo_commands=True, diff --git a/requirements_dev.txt b/requirements_dev.txt index b9bf1f8..9c102c4 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -7,6 +7,6 @@ tox==3.14.0 coverage==4.5.4 Sphinx==1.8.5 twine==1.14.0 -webexteamssdk==1.6.1 +webexpythonsdk pytest==4.6.5 pytest-runner==5.1 diff --git a/setup.py b/setup.py index 09def76..f13375a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as readme_file: readme = readme_file.read() -requirements = ['webexteamssdk==1.6.1', 'coloredlogs', 'websockets==11.0.3', 'backoff'] +requirements = ['webexpythonsdk', 'coloredlogs', 'websockets==11.0.3', 'backoff'] setup_requirements = ['pytest-runner', ] diff --git a/webex_bot/commands/echo.py b/webex_bot/commands/echo.py index 4b3bf39..b6c0dae 100644 --- a/webex_bot/commands/echo.py +++ b/webex_bot/commands/echo.py @@ -1,8 +1,8 @@ import logging -from webexteamssdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ +from webexpythonsdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ Text, Image, HorizontalAlignment -from webexteamssdk.models.cards.actions import Submit +from webexpythonsdk.models.cards.actions import Submit from webex_bot.formatting import quote_info from webex_bot.models.command import Command diff --git a/webex_bot/commands/help.py b/webex_bot/commands/help.py index 8ed6f3f..f623cb8 100644 --- a/webex_bot/commands/help.py +++ b/webex_bot/commands/help.py @@ -1,8 +1,8 @@ import logging -from webexteamssdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ +from webexpythonsdk.models.cards import Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard, ColumnSet, \ ImageSize, Image, Fact -from webexteamssdk.models.cards.actions import Submit +from webexpythonsdk.models.cards.actions import Submit from webex_bot.models.command import Command, COMMAND_KEYWORD_KEY from webex_bot.models.response import response_from_adaptive_card diff --git a/webex_bot/models/command.py b/webex_bot/models/command.py index fc20552..e925ec8 100644 --- a/webex_bot/models/command.py +++ b/webex_bot/models/command.py @@ -30,7 +30,7 @@ def __init__(self, command_keyword=None, exact_command_keyword_match=False, @param chained_commands: (optional) List of other commands related to this command. This allows multiple related cards to be added at once. @param card: (deprecated) A dict representation of the JSON card. - Prefer to use cards built in code using the webexteamssdk.models.cards classes + Prefer to use cards built in code using the webexpythonsdk.models.cards classes (see https://github.com/fbradyirl/webex_bot/blob/main/webex_bot/commands/echo.py for example) @param help_message: Short description of this command. @param delete_previous_message: If True, the card which invoked this command will be deleted. (default False) @@ -55,7 +55,7 @@ def __init__(self, command_keyword=None, exact_command_keyword_match=False, if card is not None: log.warning(f"[{command_keyword}]. Using a card dict is now deprecated. " f"Switch to use adaptive cards built in code " - "using the webexteamssdk.models.cards classes (see " + "using the webexpythonsdk.models.cards classes (see " "https://github.com/fbradyirl/webex_bot/blob/main/webex_bot/commands/echo.py for example)") if 'actions' in card: if len(card['actions']) > 0: diff --git a/webex_bot/models/response.py b/webex_bot/models/response.py index 170d557..468cd56 100644 --- a/webex_bot/models/response.py +++ b/webex_bot/models/response.py @@ -1,6 +1,6 @@ import json -from webexteamssdk.models.cards import AdaptiveCard +from webexpythonsdk.models.cards import AdaptiveCard def response_from_adaptive_card(adaptive_card: AdaptiveCard): diff --git a/webex_bot/webex_bot.py b/webex_bot/webex_bot.py index ecf346c..d7afeb7 100644 --- a/webex_bot/webex_bot.py +++ b/webex_bot/webex_bot.py @@ -5,7 +5,7 @@ import backoff import coloredlogs import requests -import webexteamssdk +import webexpythonsdk from webex_bot.commands.echo import EchoCommand from webex_bot.commands.help import HelpCommand @@ -95,7 +95,7 @@ def __init__(self, @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError) def get_me_info(self): """ - Fetch me info from webexteamssdk + Fetch me info from webexpythonsdk """ me = self.teams.people.me() self.bot_display_name = me.displayName @@ -168,7 +168,7 @@ def is_user_member_of_room(self, user_email, approved_rooms): for member in room_members: if member.personEmail == user_email: is_user_member = True - except webexteamssdk.exceptions.ApiError as apie: + except webexpythonsdk.exceptions.ApiError as apie: log.warn(f"API error: {apie}") return is_user_member diff --git a/webex_bot/websockets/webex_websocket_client.py b/webex_bot/websockets/webex_websocket_client.py index f6ee65c..6de5f6e 100644 --- a/webex_bot/websockets/webex_websocket_client.py +++ b/webex_bot/websockets/webex_websocket_client.py @@ -9,7 +9,7 @@ import certifi import requests import websockets -from webexteamssdk import WebexTeamsAPI +from webexpythonsdk import WebexAPI try: from websockets_proxy import Proxy, proxy_connect @@ -45,7 +45,7 @@ def __init__(self, on_card_action=None, proxies=None): self.access_token = access_token - self.teams = WebexTeamsAPI(access_token=access_token, proxies=proxies) + self.teams = WebexAPI(access_token=access_token, proxies=proxies) self.device_url = device_url self.device_info = None self.on_message = on_message From 67c40a1090eb7fa2b210321bb4c6d0efb78fbfac Mon Sep 17 00:00:00 2001 From: "Sakthivel Ramasamy (sakthram)" Date: Fri, 20 Dec 2024 06:56:33 +0530 Subject: [PATCH 2/2] Updated version for webexpythonsdk Point webexpythonsdk to the latest version --- requirements_dev.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 9c102c4..746db1c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -7,6 +7,6 @@ tox==3.14.0 coverage==4.5.4 Sphinx==1.8.5 twine==1.14.0 -webexpythonsdk +webexpythonsdk==2.0.2 pytest==4.6.5 pytest-runner==5.1 diff --git a/setup.py b/setup.py index f13375a..dcb1826 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as readme_file: readme = readme_file.read() -requirements = ['webexpythonsdk', 'coloredlogs', 'websockets==11.0.3', 'backoff'] +requirements = ['webexpythonsdk==2.0.2', 'coloredlogs', 'websockets==11.0.3', 'backoff'] setup_requirements = ['pytest-runner', ]