Skip to content

Commit 23ef234

Browse files
author
Finbarr Brady
committed
Merge branch 'main' of github.com:fbradyirl/webex_bot
2 parents 3ef0b93 + 66aa0ce commit 23ef234

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
[![Pypi](https://img.shields.io/pypi/v/webex_bot.svg)](https://pypi.python.org/pypi/webex_bot) [![Build Status](https://github.com/fbradyirl/webex_bot/workflows/Python%20package/badge.svg)](https://github.com/fbradyirl/webex_bot/actions)
44

5+
> [!IMPORTANT]
6+
> This repository is only sporadically maintained. Breaking API changes will be maintained on a best efforts basis.
7+
>
8+
> Collaborators are welcome, as are PRs for enhancements.
9+
>
10+
> Bug reports unrelated to API changes may not get the attention you want.
11+
12+
513
By using this module, you can create a [Webex Teams][5] messaging bot quickly in just a couple of lines of code.
614

715
This module does not require you to set up an ngrok tunnel to receive incoming messages when behind a firewall or

webex_bot/models/command.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
class Command(ABC):
1111

12-
def __init__(self, command_keyword=None, chained_commands=[], card=None, help_message=None,
13-
delete_previous_message=False,
12+
def __init__(self, command_keyword=None, exact_command_keyword_match=False,
13+
chained_commands=[], card=None,
14+
help_message=None, delete_previous_message=False,
1415
card_callback_keyword=None, approved_rooms=None):
1516
"""
1617
Create a new bot command.
@@ -25,6 +26,7 @@ def __init__(self, command_keyword=None, chained_commands=[], card=None, help_me
2526
)
2627
2728
@param command_keyword: (optional) Text indicating a phrase to invoke this card.
29+
@param exact_command_keyword_match: If True, there will be an exact command_keyword match performed. If False, then a sub-string match will be performed. Default: False.
2830
@param chained_commands: (optional) List of other commands related
2931
to this command. This allows multiple related cards to be added at once.
3032
@param card: (deprecated) A dict representation of the JSON card.
@@ -37,6 +39,7 @@ def __init__(self, command_keyword=None, chained_commands=[], card=None, help_me
3739
@param approved_rooms: If defined, only members of these spaces will be allowed to run this command. Default: None (everyone)
3840
"""
3941
self.command_keyword = command_keyword
42+
self.exact_command_keyword_match = exact_command_keyword_match
4043
self.help_message = help_message
4144
self.card = card
4245
self.pre_card_callback = self.execute

webex_bot/webex_bot.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,21 @@ def process_raw_command(self, raw_message, teams_message, user_email, activity,
234234

235235
if not is_card_callback_command and c.command_keyword:
236236
log.debug(f"c.command_keyword: {c.command_keyword}")
237-
if user_command.find(c.command_keyword) != -1:
238-
command = c
239-
# If a command was found, stop looking for others
240-
break
237+
log.info(f"exact_command_keyword_match: {c.exact_command_keyword_match}")
238+
log.info(f"user_command: {user_command}")
239+
log.info(f"command_keyword: {c.command_keyword}")
240+
if c.exact_command_keyword_match: # Check if the "exact_command_keyword_match" flag is set to True
241+
if user_command == c.command_keyword:
242+
log.info("Exact match found!")
243+
command=c
244+
# If a command was found, stop looking for others
245+
break
246+
else: # Enter here if the "exact_command_keyword_match" flag is set to False
247+
if user_command.find(c.command_keyword) != -1:
248+
log.info("Sub-string match found!")
249+
command = c
250+
# If a command was found, stop looking for others
251+
break
241252
else:
242253
log.debug(f"card_callback_keyword: {c.card_callback_keyword}")
243254
if user_command == c.command_keyword or user_command == c.card_callback_keyword:

0 commit comments

Comments
 (0)