feat: sync AI compose and ChatBot features
This commit is contained in:
parent
35e5d38f4d
commit
b7269b135f
75 changed files with 5426 additions and 123 deletions
|
|
@ -1,22 +1,8 @@
|
|||
-- Star gifts are owned by a peer, not only by users: user gifts are addressed by
|
||||
-- inputSavedStarGiftUser.msg_id, while channel gifts are addressed by
|
||||
-- inputSavedStarGiftChat{peer,saved_id}.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF to_regclass('public.user_star_gifts') IS NOT NULL
|
||||
AND to_regclass('public.peer_star_gifts') IS NULL THEN
|
||||
ALTER TABLE public.user_star_gifts RENAME TO peer_star_gifts;
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'peer_star_gifts'
|
||||
AND column_name = 'owner_user_id'
|
||||
) THEN
|
||||
ALTER TABLE public.peer_star_gifts RENAME COLUMN owner_user_id TO owner_peer_id;
|
||||
END IF;
|
||||
END $$;
|
||||
ALTER TABLE public.user_star_gifts RENAME TO peer_star_gifts;
|
||||
ALTER TABLE public.peer_star_gifts RENAME COLUMN owner_user_id TO owner_peer_id;
|
||||
|
||||
ALTER TABLE public.peer_star_gifts
|
||||
ADD COLUMN IF NOT EXISTS owner_peer_type text DEFAULT 'user' NOT NULL,
|
||||
|
|
|
|||
2
deploy/migrations/0046_ai_compose.down.sql
Normal file
2
deploy/migrations/0046_ai_compose.down.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DROP TABLE IF EXISTS ai_compose_tone_saves;
|
||||
DROP TABLE IF EXISTS ai_compose_tones;
|
||||
38
deploy/migrations/0046_ai_compose.up.sql
Normal file
38
deploy/migrations/0046_ai_compose.up.sql
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
CREATE TABLE IF NOT EXISTS ai_compose_tones (
|
||||
id BIGINT PRIMARY KEY,
|
||||
access_hash BIGINT NOT NULL,
|
||||
owner_user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
title TEXT NOT NULL,
|
||||
emoji_id BIGINT NOT NULL DEFAULT 0,
|
||||
prompt TEXT NOT NULL,
|
||||
display_author BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
installs_count INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CHECK (id > 0),
|
||||
CHECK (access_hash <> 0),
|
||||
CHECK (owner_user_id > 0),
|
||||
CHECK (slug <> ''),
|
||||
CHECK (title <> ''),
|
||||
CHECK (prompt <> ''),
|
||||
CHECK (char_length(title) <= 12),
|
||||
CHECK (char_length(prompt) <= 1024),
|
||||
CHECK (installs_count >= 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ai_compose_tones_access_hash_idx
|
||||
ON ai_compose_tones(id, access_hash);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ai_compose_tones_owner_updated_idx
|
||||
ON ai_compose_tones(owner_user_id, updated_at DESC, id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_compose_tone_saves (
|
||||
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
tone_id BIGINT NOT NULL REFERENCES ai_compose_tones(id) ON DELETE CASCADE,
|
||||
saved_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (user_id, tone_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ai_compose_tone_saves_user_saved_idx
|
||||
ON ai_compose_tone_saves(user_id, saved_at, tone_id);
|
||||
19
deploy/migrations/0047_chatbot_service_bot.down.sql
Normal file
19
deploy/migrations/0047_chatbot_service_bot.down.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
DELETE FROM public.read_model_versions
|
||||
WHERE owner_user_id = 1250000007
|
||||
AND peer_type = 'user'
|
||||
AND peer_id = 1250000007
|
||||
AND model IN ('contact_account', 'channel_active_memberships');
|
||||
|
||||
DELETE FROM public.peer_usernames
|
||||
WHERE username_lower = 'chatbot'
|
||||
AND peer_type = 'user'
|
||||
AND peer_id = 1250000007;
|
||||
|
||||
DELETE FROM public.bots
|
||||
WHERE bot_user_id = 1250000007
|
||||
AND owner_user_id = 1250000007;
|
||||
|
||||
DELETE FROM public.users
|
||||
WHERE id = 1250000007
|
||||
AND username = 'ChatBot'
|
||||
AND is_bot = true;
|
||||
68
deploy/migrations/0047_chatbot_service_bot.up.sql
Normal file
68
deploy/migrations/0047_chatbot_service_bot.up.sql
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
INSERT INTO public.users (
|
||||
id, access_hash, phone, first_name, last_name, username, country_code,
|
||||
created_at, updated_at, verified, support, about, last_seen_at,
|
||||
default_history_ttl_period, is_bot, bot_info_version, premium_expires_at,
|
||||
emoji_status_document_id, emoji_status_until, color_set, color,
|
||||
color_background_emoji_id, profile_color_set, profile_color,
|
||||
profile_color_background_emoji_id
|
||||
) VALUES (
|
||||
1250000007, 6332902371644871201, '', 'ChatBot', '', 'ChatBot', '',
|
||||
now(), now(), true, false, 'Chat with the configured telesrv AI provider.',
|
||||
0, 0, true, 1, NULL, 0, 0, false, 0, 0, false, 0, 0
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
access_hash = EXCLUDED.access_hash,
|
||||
phone = EXCLUDED.phone,
|
||||
first_name = EXCLUDED.first_name,
|
||||
last_name = EXCLUDED.last_name,
|
||||
username = EXCLUDED.username,
|
||||
verified = EXCLUDED.verified,
|
||||
support = EXCLUDED.support,
|
||||
about = EXCLUDED.about,
|
||||
is_bot = EXCLUDED.is_bot,
|
||||
bot_info_version = GREATEST(public.users.bot_info_version, EXCLUDED.bot_info_version),
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.bots (
|
||||
bot_user_id, owner_user_id, token_secret, description, commands,
|
||||
bot_chat_history, bot_nochats, inline_placeholder, created_at, updated_at,
|
||||
menu_button_type, menu_button_text, menu_button_url, bot_inline_geo
|
||||
) VALUES (
|
||||
1250000007, 1250000007, '',
|
||||
'Chat with the configured telesrv AI provider.',
|
||||
'[
|
||||
{"command": "start", "description": "start chatting"},
|
||||
{"command": "help", "description": "show help"},
|
||||
{"command": "reset", "description": "clear local chat context"}
|
||||
]'::jsonb,
|
||||
false, false, '', now(), now(), 0, '', '', false
|
||||
)
|
||||
ON CONFLICT (bot_user_id) DO UPDATE SET
|
||||
owner_user_id = EXCLUDED.owner_user_id,
|
||||
token_secret = EXCLUDED.token_secret,
|
||||
description = EXCLUDED.description,
|
||||
commands = EXCLUDED.commands,
|
||||
bot_chat_history = EXCLUDED.bot_chat_history,
|
||||
bot_nochats = EXCLUDED.bot_nochats,
|
||||
inline_placeholder = EXCLUDED.inline_placeholder,
|
||||
menu_button_type = EXCLUDED.menu_button_type,
|
||||
menu_button_text = EXCLUDED.menu_button_text,
|
||||
menu_button_url = EXCLUDED.menu_button_url,
|
||||
bot_inline_geo = EXCLUDED.bot_inline_geo,
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.peer_usernames (username_lower, peer_type, peer_id, updated_at)
|
||||
VALUES ('chatbot', 'user', 1250000007, now())
|
||||
ON CONFLICT (username_lower) DO UPDATE SET
|
||||
peer_type = EXCLUDED.peer_type,
|
||||
peer_id = EXCLUDED.peer_id,
|
||||
updated_at = now();
|
||||
|
||||
INSERT INTO public.read_model_versions (model, owner_user_id, peer_type, peer_id, version, updated_at, hash)
|
||||
VALUES
|
||||
('contact_account', 1250000007, 'user', 1250000007, 1, now(), 2500000700001),
|
||||
('channel_active_memberships', 1250000007, 'user', 1250000007, 1, now(), 2500000700002)
|
||||
ON CONFLICT (model, owner_user_id, peer_type, peer_id) DO UPDATE SET
|
||||
version = GREATEST(public.read_model_versions.version, EXCLUDED.version),
|
||||
updated_at = now(),
|
||||
hash = EXCLUDED.hash;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE message_boxes
|
||||
DROP COLUMN IF EXISTS hide_edited;
|
||||
|
||||
ALTER TABLE private_messages
|
||||
DROP COLUMN IF EXISTS hide_edited;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE private_messages
|
||||
ADD COLUMN hide_edited boolean DEFAULT false NOT NULL;
|
||||
|
||||
ALTER TABLE message_boxes
|
||||
ADD COLUMN hide_edited boolean DEFAULT false NOT NULL;
|
||||
12
deploy/migrations/0049_chatbot_hide_existing_edits.down.sql
Normal file
12
deploy/migrations/0049_chatbot_hide_existing_edits.down.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
UPDATE message_boxes
|
||||
SET hide_edited = false
|
||||
WHERE message_sender_id = 1250000007
|
||||
AND from_user_id = 1250000007
|
||||
AND edit_date > 0
|
||||
AND hide_edited;
|
||||
|
||||
UPDATE private_messages
|
||||
SET hide_edited = false
|
||||
WHERE sender_user_id = 1250000007
|
||||
AND edit_date > 0
|
||||
AND hide_edited;
|
||||
12
deploy/migrations/0049_chatbot_hide_existing_edits.up.sql
Normal file
12
deploy/migrations/0049_chatbot_hide_existing_edits.up.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
UPDATE private_messages
|
||||
SET hide_edited = true
|
||||
WHERE sender_user_id = 1250000007
|
||||
AND edit_date > 0
|
||||
AND NOT hide_edited;
|
||||
|
||||
UPDATE message_boxes
|
||||
SET hide_edited = true
|
||||
WHERE message_sender_id = 1250000007
|
||||
AND from_user_id = 1250000007
|
||||
AND edit_date > 0
|
||||
AND NOT hide_edited;
|
||||
Loading…
Add table
Add a link
Reference in a new issue