From 2ccc0775b7fea017f461fae355e70d60d0156917 Mon Sep 17 00:00:00 2001 From: SAKTHIVEL RAMASAMY <53861448+Sakthivel-Ramasamy@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:33:16 +0530 Subject: [PATCH] Migrate from "webexteamssdk" library to "webexpythonsdk" library (#62) * 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". * Updated version for webexpythonsdk Point webexpythonsdk to the latest version --------- Co-authored-by: Sakthivel Ramasamy (sakthram) Co-authored-by: FB --- README.md | 12 ++++++------ example.py | 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 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bab83e7..850f4c5 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 @@ -371,7 +371,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/setup.py b/setup.py index 09def76..dcb1826 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==2.0.2', '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