feat: sync bot keyboards and callbacks
Sync telesrv b96f2dd (feat(bot): complete keyboards callbacks and durable delivery). Skipped private docs and preserved public README files per sync rules; normalized the appearance seed log label for public naming.
This commit is contained in:
parent
0c99ae0a9d
commit
bf965f610c
80 changed files with 7212 additions and 349 deletions
20
deploy/migrations/0110_bot_api_callback_queries.down.sql
Normal file
20
deploy/migrations/0110_bot_api_callback_queries.down.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
DELETE FROM public.bot_api_updates WHERE update_kind = 'callback_query';
|
||||
|
||||
DROP INDEX IF EXISTS public.bot_api_updates_callback_query_unique;
|
||||
DROP INDEX IF EXISTS public.bot_api_updates_message_source_unique;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP CONSTRAINT bot_api_updates_callback_shape_check,
|
||||
DROP CONSTRAINT bot_api_updates_kind_check;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
ADD CONSTRAINT bot_api_updates_kind_check
|
||||
CHECK ((update_kind)::text = ANY (ARRAY['message'::text, 'edited_message'::text])),
|
||||
ADD CONSTRAINT bot_api_updates_source_unique
|
||||
UNIQUE (bot_user_id, update_kind, peer_type, peer_id, message_id, source_pts);
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP COLUMN callback_data,
|
||||
DROP COLUMN callback_chat_instance,
|
||||
DROP COLUMN callback_user_id,
|
||||
DROP COLUMN callback_query_id;
|
||||
35
deploy/migrations/0110_bot_api_callback_queries.up.sql
Normal file
35
deploy/migrations/0110_bot_api_callback_queries.up.sql
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
ALTER TABLE public.bot_api_updates
|
||||
ADD COLUMN callback_query_id bigint NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_user_id bigint NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_chat_instance bigint NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_data bytea;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP CONSTRAINT bot_api_updates_kind_check,
|
||||
DROP CONSTRAINT bot_api_updates_source_unique;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
ADD CONSTRAINT bot_api_updates_kind_check
|
||||
CHECK ((update_kind)::text = ANY (ARRAY['message'::text, 'edited_message'::text, 'callback_query'::text])),
|
||||
ADD CONSTRAINT bot_api_updates_callback_shape_check CHECK (
|
||||
(update_kind = 'callback_query'
|
||||
AND callback_query_id <> 0
|
||||
AND callback_user_id > 0
|
||||
AND callback_chat_instance <> 0
|
||||
AND COALESCE(octet_length(callback_data), 0) <= 64
|
||||
AND source_pts = 0)
|
||||
OR
|
||||
(update_kind IN ('message', 'edited_message')
|
||||
AND callback_query_id = 0
|
||||
AND callback_user_id = 0
|
||||
AND callback_chat_instance = 0
|
||||
AND callback_data IS NULL)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX bot_api_updates_message_source_unique
|
||||
ON public.bot_api_updates (bot_user_id, update_kind, peer_type, peer_id, message_id, source_pts)
|
||||
WHERE update_kind IN ('message', 'edited_message');
|
||||
|
||||
CREATE UNIQUE INDEX bot_api_updates_callback_query_unique
|
||||
ON public.bot_api_updates (bot_user_id, callback_query_id)
|
||||
WHERE update_kind = 'callback_query';
|
||||
6
deploy/migrations/0111_bot_api_polling_state.down.sql
Normal file
6
deploy/migrations/0111_bot_api_polling_state.down.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
DROP INDEX IF EXISTS public.bot_api_updates_created_retention_idx;
|
||||
|
||||
ALTER TABLE public.bot_api_update_states
|
||||
DROP CONSTRAINT IF EXISTS bot_api_update_states_allowed_updates_check,
|
||||
DROP COLUMN IF EXISTS cursor_initialized,
|
||||
DROP COLUMN IF EXISTS allowed_updates;
|
||||
12
deploy/migrations/0111_bot_api_polling_state.up.sql
Normal file
12
deploy/migrations/0111_bot_api_polling_state.up.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
ALTER TABLE public.bot_api_update_states
|
||||
ADD COLUMN allowed_updates text[],
|
||||
ADD COLUMN cursor_initialized boolean NOT NULL DEFAULT false;
|
||||
|
||||
ALTER TABLE public.bot_api_update_states
|
||||
ADD CONSTRAINT bot_api_update_states_allowed_updates_check CHECK (
|
||||
allowed_updates IS NULL
|
||||
OR array_position(allowed_updates, NULL) IS NULL
|
||||
);
|
||||
|
||||
CREATE INDEX bot_api_updates_created_retention_idx
|
||||
ON public.bot_api_updates (created_at, id);
|
||||
4
deploy/migrations/0112_bot_api_poll_lease.down.sql
Normal file
4
deploy/migrations/0112_bot_api_poll_lease.down.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE public.bot_api_update_states
|
||||
DROP CONSTRAINT IF EXISTS bot_api_update_states_poll_lease_check,
|
||||
DROP COLUMN IF EXISTS poll_expires_at,
|
||||
DROP COLUMN IF EXISTS poll_owner;
|
||||
10
deploy/migrations/0112_bot_api_poll_lease.up.sql
Normal file
10
deploy/migrations/0112_bot_api_poll_lease.up.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ALTER TABLE public.bot_api_update_states
|
||||
ADD COLUMN poll_owner text NOT NULL DEFAULT '',
|
||||
ADD COLUMN poll_expires_at timestamptz;
|
||||
|
||||
ALTER TABLE public.bot_api_update_states
|
||||
ADD CONSTRAINT bot_api_update_states_poll_lease_check CHECK (
|
||||
(poll_owner = '' AND poll_expires_at IS NULL)
|
||||
OR
|
||||
(poll_owner <> '' AND poll_expires_at IS NOT NULL)
|
||||
);
|
||||
27
deploy/migrations/0113_bot_api_inline_callbacks.down.sql
Normal file
27
deploy/migrations/0113_bot_api_inline_callbacks.down.sql
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
DELETE FROM public.bot_api_updates
|
||||
WHERE update_kind = 'callback_query' AND callback_inline_message_id <> 0;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP CONSTRAINT bot_api_updates_callback_shape_check,
|
||||
DROP CONSTRAINT bot_api_updates_peer_type_check,
|
||||
DROP CONSTRAINT bot_api_updates_peer_id_check,
|
||||
DROP CONSTRAINT bot_api_updates_message_id_check;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
ADD CONSTRAINT bot_api_updates_peer_type_check CHECK (peer_type IN ('user', 'channel')),
|
||||
ADD CONSTRAINT bot_api_updates_peer_id_check CHECK (peer_id > 0),
|
||||
ADD CONSTRAINT bot_api_updates_message_id_check CHECK (message_id > 0),
|
||||
ADD CONSTRAINT bot_api_updates_callback_shape_check CHECK (
|
||||
(update_kind = 'callback_query' AND callback_query_id <> 0 AND callback_user_id > 0
|
||||
AND callback_chat_instance <> 0 AND COALESCE(octet_length(callback_data), 0) <= 64
|
||||
AND source_pts = 0)
|
||||
OR
|
||||
(update_kind IN ('message', 'edited_message') AND callback_query_id = 0
|
||||
AND callback_user_id = 0 AND callback_chat_instance = 0 AND callback_data IS NULL)
|
||||
);
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP COLUMN callback_inline_access_hash,
|
||||
DROP COLUMN callback_inline_message_id,
|
||||
DROP COLUMN callback_inline_owner_id,
|
||||
DROP COLUMN callback_inline_dc_id;
|
||||
49
deploy/migrations/0113_bot_api_inline_callbacks.up.sql
Normal file
49
deploy/migrations/0113_bot_api_inline_callbacks.up.sql
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
ALTER TABLE public.bot_api_updates
|
||||
ADD COLUMN callback_inline_dc_id integer NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_inline_owner_id bigint NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_inline_message_id integer NOT NULL DEFAULT 0,
|
||||
ADD COLUMN callback_inline_access_hash bigint NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
DROP CONSTRAINT bot_api_updates_callback_shape_check,
|
||||
DROP CONSTRAINT bot_api_updates_peer_type_check,
|
||||
DROP CONSTRAINT bot_api_updates_peer_id_check,
|
||||
DROP CONSTRAINT bot_api_updates_message_id_check;
|
||||
|
||||
ALTER TABLE public.bot_api_updates
|
||||
ADD CONSTRAINT bot_api_updates_peer_type_check CHECK (
|
||||
peer_type IN ('user', 'channel')
|
||||
OR (update_kind = 'callback_query' AND peer_type = '')
|
||||
),
|
||||
ADD CONSTRAINT bot_api_updates_peer_id_check CHECK (
|
||||
peer_id > 0
|
||||
OR (update_kind = 'callback_query' AND peer_id = 0)
|
||||
),
|
||||
ADD CONSTRAINT bot_api_updates_message_id_check CHECK (
|
||||
message_id > 0
|
||||
OR (update_kind = 'callback_query' AND message_id = 0)
|
||||
),
|
||||
ADD CONSTRAINT bot_api_updates_callback_shape_check CHECK (
|
||||
(update_kind = 'callback_query'
|
||||
AND callback_query_id <> 0
|
||||
AND callback_user_id > 0
|
||||
AND callback_chat_instance <> 0
|
||||
AND COALESCE(octet_length(callback_data), 0) <= 64
|
||||
AND source_pts = 0
|
||||
AND (
|
||||
(peer_type IN ('user', 'channel') AND peer_id > 0 AND message_id > 0
|
||||
AND callback_inline_dc_id = 0 AND callback_inline_owner_id = 0
|
||||
AND callback_inline_message_id = 0 AND callback_inline_access_hash = 0)
|
||||
OR
|
||||
(peer_type = '' AND peer_id = 0 AND message_id = 0
|
||||
AND callback_inline_dc_id > 0 AND callback_inline_owner_id > 0
|
||||
AND callback_inline_message_id > 0 AND callback_inline_access_hash <> 0)
|
||||
))
|
||||
OR
|
||||
(update_kind IN ('message', 'edited_message')
|
||||
AND peer_type IN ('user', 'channel') AND peer_id > 0 AND message_id > 0
|
||||
AND callback_query_id = 0 AND callback_user_id = 0
|
||||
AND callback_chat_instance = 0 AND callback_data IS NULL
|
||||
AND callback_inline_dc_id = 0 AND callback_inline_owner_id = 0
|
||||
AND callback_inline_message_id = 0 AND callback_inline_access_hash = 0)
|
||||
);
|
||||
1
deploy/migrations/0115_bot_api_webhooks.down.sql
Normal file
1
deploy/migrations/0115_bot_api_webhooks.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS public.bot_api_webhooks;
|
||||
27
deploy/migrations/0115_bot_api_webhooks.up.sql
Normal file
27
deploy/migrations/0115_bot_api_webhooks.up.sql
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
CREATE TABLE public.bot_api_webhooks (
|
||||
bot_user_id bigint PRIMARY KEY REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
url text NOT NULL,
|
||||
secret_token varchar(256) NOT NULL DEFAULT '',
|
||||
max_connections integer NOT NULL DEFAULT 40,
|
||||
allowed_updates text[],
|
||||
failure_count integer NOT NULL DEFAULT 0,
|
||||
last_error_date integer NOT NULL DEFAULT 0,
|
||||
last_error_message varchar(512) NOT NULL DEFAULT '',
|
||||
next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
||||
delivery_owner text NOT NULL DEFAULT '',
|
||||
delivery_expires_at timestamptz,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT bot_api_webhooks_url_check CHECK (length(url) BETWEEN 1 AND 2048),
|
||||
CONSTRAINT bot_api_webhooks_max_connections_check CHECK (max_connections BETWEEN 1 AND 100),
|
||||
CONSTRAINT bot_api_webhooks_failure_count_check CHECK (failure_count >= 0),
|
||||
CONSTRAINT bot_api_webhooks_allowed_updates_check CHECK (
|
||||
allowed_updates IS NULL OR array_position(allowed_updates, NULL) IS NULL
|
||||
),
|
||||
CONSTRAINT bot_api_webhooks_delivery_lease_check CHECK (
|
||||
(delivery_owner = '' AND delivery_expires_at IS NULL)
|
||||
OR (delivery_owner <> '' AND delivery_expires_at IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX bot_api_webhooks_due_idx
|
||||
ON public.bot_api_webhooks (next_attempt_at, bot_user_id);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE public.webview_requested_buttons
|
||||
DROP COLUMN IF EXISTS peer_filter;
|
||||
2
deploy/migrations/0116_bot_requested_peer_filters.up.sql
Normal file
2
deploy/migrations/0116_bot_requested_peer_filters.up.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE public.webview_requested_buttons
|
||||
ADD COLUMN peer_filter jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE public.webview_requested_buttons
|
||||
DROP COLUMN IF EXISTS photo_requested,
|
||||
DROP COLUMN IF EXISTS username_requested,
|
||||
DROP COLUMN IF EXISTS name_requested;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE public.webview_requested_buttons
|
||||
ADD COLUMN name_requested boolean NOT NULL DEFAULT false,
|
||||
ADD COLUMN username_requested boolean NOT NULL DEFAULT false,
|
||||
ADD COLUMN photo_requested boolean NOT NULL DEFAULT false;
|
||||
Loading…
Add table
Add a link
Reference in a new issue