fbradyirl / webex_bot

Python package for a Webex Bot based on websockets.
MIT License
68 stars 44 forks source link

How can we make bot to listen and respond to messages which do not reffer directly to it? Without bot being tagget in the message #36

Open un1v3rs opened 1 year ago

gconklin commented 1 year ago

The Webex bots do not allow this by design. From https://developer.webex.com/docs/api/guides/bots :

A bot can only access messages sent to it directly. In group spaces, bots must be @mentioned to access the message. In 1-to-1 spaces, a bot has access to all messages from the user.

Integrations (https://developer.webex.com/docs/integrations) can be used to process messages that do not require @mentions, but is because integrations act on behalf of a user.

un1v3rs commented 1 year ago

Thank you. Is there any python library that can support this "integrations"? I would like to make a Bot/Intergation that would check in the messages of the room for specific words in order to take actions

gconklin commented 1 year ago

It's the same API, just a different, more complex authentication mechanism. Theoretically, you could create the auth tokens outside of this library for use with this library, though not directly supported (I suspect)

gconklin commented 1 year ago

Specific to your question, I don't personally know of a library that works directly with the auth flow to make an integration.

There are examples about the oauth flow:

un1v3rs commented 1 year ago

Let me give you another scenario. Let me know please if it works. Lets say that a service is sending via a bot (called XXX) a message to a webex channel. If I run your script with the token of the same XXX bot, is it going to read and react on messages sent by the same XXX bot but via the service from above? I mean the same bot and tokens are used by two in the same time.

gconklin commented 1 year ago

I'm not exactly sure if I understand your question, but when messages come in, they have metadata such as the user/entity e-mail address that sent the message. With that metadata, you can filter the messages to prevent bots from talking to other bots or allow only certain users to interact with the bot.

un1v3rs commented 1 year ago

I have run your script with the bot token which is set by another service. Once the bot is sending a message via the service, your script is showing me an event with the following text: "Websocket ack message with ID=xxx. Completed'". Question: How can i tune your demo script in order to run action based on the content of the message which was sent by the service (using the same bot token)? Can your libabry read the message which was sent by a other service? It the same bot for service and your demo script. Thank you

un1v3rs commented 1 year ago

Btw, how can I turn on the Debug mode? How i see only INFO messages. Thanks

darrenparkinson commented 1 year ago

If you used the bot token to send a message from elsewhere and you're using the same bot token to receive notifications, then yes, my understanding is that you'd be able to retrieve that message using the bot token.

un1v3rs commented 1 year ago

Thank so much, that answers to my question. What would be the simplest code that would respond to echo comand with a text? I see your demo include more complex case by returning adaptive cards...

darrenparkinson commented 1 year ago

Hi, I haven't used this particular library yet, but it looks like you can just create a Response object and pass in the relevant attributes, such as "text"?:

response = Response()
response.text = "Your message here"
fbradyirl commented 1 year ago

Yes or even simplier just reply with a string.

un1v3rs commented 1 year ago

I was able to make what I want. In term of making your script to react on a message which a Bot has created via another service.

Another question here: how can I make Bot to reply to a message? In your case Bot is creating a new message, however I want Bot to reply to a message where he was mentioned into. Thanks