There are times -like when you are first developing it, or when it is handling sensitive information -when you want your bot to beonlyavailable ANDonlyrespond to folks within your company. Unfortunately, Webex Teams does not yet have the ability to restrict anyone from adding your bot to a space so we need to make sure you don't respond to everyone.
You can take steps to make sure your bot does not respond to messages within a space where there are folks from other organizations. At runtime I typically use the spark helper membership check function before responding to a message from a room. The code can be found in the CiscoSE GitHub repository. It's kind of like telling your kids to NOT open the door every time someone rings the door bell!
Unfortunately, this is reactive, so why don't we be a bit more proactive and leverage the same great Webex Team's API's with solution that can be automated?
The basic idea behind the algorithm is as follows:
Pretty simple, so let's take a look at the code.
First, let's define a function calledcheck_and_delete_membershipand let's pass it the bot's access token and the Webex Team's organization ID. With this helpful information, let's exercise the Webex Team's Membership API a bit to get the party started.
[cc lang="python" width="700