mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
embedded bots: Add functional state handler.
This replaces the former non-functional StateHandler stub with a dictionary-like state object. Accessing it will will read and store strings in the BotUserStateData model. Each bot has a limited state size. To enforce this limit while keeping data updates efficient, StateHandler caches the expensive query for getting a bot's total state size. Assignments to a key then only need to fetch that entry's previous size, if any, and compare it to the new entry's size.
This commit is contained in:
@@ -9,7 +9,6 @@ from functools import wraps
|
||||
import smtplib
|
||||
import socket
|
||||
|
||||
from zulip_bots.lib import ExternalBotHandler, StateHandler
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
@@ -506,11 +505,6 @@ class EmbeddedBotWorker(QueueProcessingWorker):
|
||||
# type: (UserProfile) -> EmbeddedBotHandler
|
||||
return EmbeddedBotHandler(user_profile)
|
||||
|
||||
# TODO: Handle stateful bots properly
|
||||
def get_state_handler(self):
|
||||
# type: () -> StateHandler
|
||||
return StateHandler()
|
||||
|
||||
def consume(self, event):
|
||||
# type: (Mapping[str, Any]) -> None
|
||||
user_profile_id = event['user_profile_id']
|
||||
@@ -528,4 +522,4 @@ class EmbeddedBotWorker(QueueProcessingWorker):
|
||||
bot_handler.handle_message(
|
||||
message=message,
|
||||
bot_handler=self.get_bot_api_client(user_profile),
|
||||
state_handler=self.get_state_handler())
|
||||
state_handler=None)
|
||||
|
||||
Reference in New Issue
Block a user