Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use typed command in BotCommandClaims #7113

Merged
merged 41 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e9a0f14
Greet bot sample phase 1 WIP
megrogan Dec 23, 2024
ca23f3d
Try to get build to work on github!
megrogan Dec 23, 2024
0912a38
Try to fix build
megrogan Dec 23, 2024
9df6746
Revert
megrogan Dec 23, 2024
7cf0dc6
bump
megrogan Dec 23, 2024
1850275
bump
megrogan Dec 23, 2024
6641f16
Merge remote-tracking branch 'origin/master' into bot
megrogan Dec 23, 2024
c56d9c7
Call OC async and return message immediately
megrogan Dec 23, 2024
f48319a
Merge remote-tracking branch 'origin/master' into bot
megrogan Dec 23, 2024
0ff62a7
Return response enum regardless of HTTP code
megrogan Dec 30, 2024
725e016
Merge remote-tracking branch 'origin/master' into bot
megrogan Jan 2, 2025
0e5fd86
Add joke command to greet bot
megrogan Jan 6, 2025
8503eed
Merge remote-tracking branch 'origin/master' into bot
megrogan Jan 6, 2025
44b3b19
WIP
megrogan Jan 7, 2025
e43184e
Merge remote-tracking branch 'origin/master' into bot
megrogan Jan 7, 2025
07e2281
Merge branch 'bot2' into bot
megrogan Jan 7, 2025
8bd2368
No openchat dependencies
megrogan Jan 8, 2025
575b414
Merge branch 'master' into bot
megrogan Jan 8, 2025
03a4fb9
Remove spurious change
megrogan Jan 8, 2025
b586711
Merge branch 'bot' of github.com:dfinity-lab/open-chat into bot
megrogan Jan 8, 2025
66fb26d
Remove more spurious changes
megrogan Jan 8, 2025
406b40e
fmt
megrogan Jan 8, 2025
de87bc4
Consolidate bot libraries into one SDK lib
megrogan Jan 8, 2025
88a091b
Merge branch 'master' into bot
megrogan Jan 8, 2025
018b47c
Organise into SDK projects
megrogan Jan 9, 2025
09b41fc
Use typed command in `BotCommandClaims`
megrogan Jan 10, 2025
d57d090
Merge remote-tracking branch 'origin/master' into bot
megrogan Jan 10, 2025
563529b
CHANGELOGs
megrogan Jan 10, 2025
e6350d4
Merge branch 'master' into bot
megrogan Jan 10, 2025
e858bfd
Renaming
megrogan Jan 10, 2025
a0094ea
Merge branch 'bot' of github.com:dfinity-lab/open-chat into bot
megrogan Jan 10, 2025
5fccaca
Renaming
megrogan Jan 10, 2025
17c55d7
Undo greet_bot changes
megrogan Jan 10, 2025
55a0f3f
Renaming
megrogan Jan 10, 2025
d4c17ad
Rename
megrogan Jan 10, 2025
f580f52
Rename
megrogan Jan 10, 2025
d2063ca
Fix
megrogan Jan 10, 2025
7509438
Fix candid
megrogan Jan 10, 2025
0a8aaa7
Keep User rather than Principal for command arg
megrogan Jan 10, 2025
5fd967b
Remove spurious test
megrogan Jan 10, 2025
3b77ad0
Remove unused imports
megrogan Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[workspace]
members = [
"backend/benchmarks",
"backend/bots/api",
"backend/bots/c2c_client",
"backend/canisters/airdrop_bot/api",
"backend/canisters/airdrop_bot/client",
"backend/canisters/airdrop_bot/impl",
Expand Down Expand Up @@ -110,6 +108,8 @@ members = [
"backend/external_canisters/sonic/api",
"backend/external_canisters/sonic/c2c_client",
"backend/integration_tests",
"backend/legacy_bots/api",
"backend/legacy_bots/c2c_client",
"backend/libraries/activity_notification_state",
"backend/libraries/candid_gen",
"backend/libraries/canister_agent_utils",
Expand Down Expand Up @@ -191,6 +191,7 @@ futures = "0.3.30"
getrandom = { version = "0.2.15", features = ["custom"] }
hex = "0.4.3"
hmac-sha256 = { version = "1.1.7", features = ["traits010"] }
http = "1.1.0"
ic-agent = "0.39.1"
ic-canister-sig-creation = "1.1.0"
ic-captcha = "1.0.0"
Expand All @@ -200,6 +201,7 @@ ic-cdk-macros = "0.17.0"
ic-cdk-timers = "0.11.0"
ic-certificate-verification = "2.4.0"
ic-certification = "2.5.0"
ic-http-certification = "2.5.0"
ic-ledger-types = "0.14.0"
ic_principal = "0.1.1"
ic-stable-structures = "0.6.7"
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/airdrop_bot/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bot_api = { path = "../../../bots/api" }
legacy_bot_api = { path = "../../../legacy_bots/api" }
candid = { workspace = true }
candid_gen = { path = "../../../libraries/candid_gen" }
serde = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use bot_api::handle_direct_message::{Response::*, *};
pub use legacy_bot_api::handle_direct_message::{Response::*, *};
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Log response if `delete_channel` fails ([#7152](https://github.com/open-chat-labs/open-chat/pull/7152))
- Introduce `StableMemoryMap` trait to simplify storing in stable memory ([#7176](https://github.com/open-chat-labs/open-chat/pull/7176))
- When disappearing messages expire delete any linked files ([#7184](https://github.com/open-chat-labs/open-chat/pull/7184))
- Use typed command in `BotCommandClaims` ([#7113](https://github.com/open-chat-labs/open-chat/pull/7113))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use canister_api_macros::query;
use community_canister::c2c_can_issue_access_token_for_channel::*;
use group_chat_core::{GroupChatCore, GroupRoleInternal};
use types::{CheckAccessTokenType, VideoCallType};
use utils::bots::can_execute_bot_command;
use utils::bots::can_bot_execute_action;

#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_can_issue_access_token_for_channel(args: Args) -> Response {
Expand Down Expand Up @@ -37,7 +37,7 @@ fn c2c_can_issue_access_token_for_channel_impl(args: Args, state: &RuntimeState)
return false;
};

can_execute_bot_command(&c.permissions, granted_to_bot, &granted_to_user)
can_bot_execute_action(&c.permissions, granted_to_bot, &granted_to_user)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use community_canister::c2c_handle_bot_action::*;
use community_canister::send_message;
use types::bot_actions::MessageContent;
use types::{BotAction, BotCaller, Chat, HandleBotActionsError, MessageContentInitial};
use utils::bots::can_execute_bot_command;
use utils::bots::can_bot_execute_action;

#[update(guard = "caller_is_local_user_index", msgpack = true)]
#[trace]
Expand All @@ -22,7 +22,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
return Err(HandleBotActionsError::Frozen);
}

if !is_bot_permitted_to_execute_command(&args, state) {
if !is_bot_permitted_to_execute_action(&args, state) {
return Err(HandleBotActionsError::NotAuthorized);
}

Expand Down Expand Up @@ -62,7 +62,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
Some(BotCaller {
bot: args.bot.user_id,
initiator: args.initiator,
command_text: args.command_text,
command: args.command,
finalised: action.finalised,
}),
state,
Expand All @@ -74,7 +74,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
}
}

fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> bool {
fn is_bot_permitted_to_execute_action(args: &Args, state: &RuntimeState) -> bool {
let Chat::Channel(_, channel_id) = args.chat else {
unreachable!()
};
Expand All @@ -92,5 +92,5 @@ fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> boo
// Get the permissions required to execute the given action
let permissions_required = args.action.permissions_required();

can_execute_bot_command(&permissions_required, granted_to_bot, &granted_to_user)
can_bot_execute_action(&permissions_required, granted_to_bot, &granted_to_user)
}
1 change: 1 addition & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Log error if tip fails due to recipient mismatch ([#7151](https://github.com/open-chat-labs/open-chat/pull/7151))
- Introduce `StableMemoryMap` trait to simplify storing in stable memory ([#7176](https://github.com/open-chat-labs/open-chat/pull/7176))
- When disappearing messages expire delete any linked files ([#7184](https://github.com/open-chat-labs/open-chat/pull/7184))
- Use typed command in `BotCommandClaims` ([#7113](https://github.com/open-chat-labs/open-chat/pull/7113))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use canister_api_macros::query;
use group_canister::c2c_can_issue_access_token::*;
use group_chat_core::{GroupChatCore, GroupRoleInternal};
use types::{CheckAccessTokenType, VideoCallType};
use utils::bots::can_execute_bot_command;
use utils::bots::can_bot_execute_action;

#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_can_issue_access_token(args: Args) -> Response {
Expand All @@ -31,7 +31,7 @@ fn c2c_can_issue_access_token_impl(args: Args, state: &RuntimeState) -> bool {
return false;
};

can_execute_bot_command(&c.permissions, granted_to_bot, &granted_to_user)
can_bot_execute_action(&c.permissions, granted_to_bot, &granted_to_user)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use group_canister::send_message_v2;
use types::bot_actions::MessageContent;
use types::HandleBotActionsError;
use types::{BotAction, BotCaller, MessageContentInitial};
use utils::bots::can_execute_bot_command;
use utils::bots::can_bot_execute_action;

#[update(guard = "caller_is_local_user_index", msgpack = true)]
#[trace]
Expand All @@ -23,7 +23,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
return Err(HandleBotActionsError::Frozen);
}

if !is_bot_permitted_to_execute_command(&args, state) {
if !is_bot_permitted_to_execute_action(&args, state) {
return Err(HandleBotActionsError::NotAuthorized);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
Some(BotCaller {
bot: args.bot.user_id,
initiator: args.initiator,
command_text: args.command_text,
command: args.command,
finalised: action.finalised,
}),
state,
Expand All @@ -70,7 +70,7 @@ fn c2c_handle_bot_action_impl(args: Args, state: &mut RuntimeState) -> Response
}
}

fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> bool {
fn is_bot_permitted_to_execute_action(args: &Args, state: &RuntimeState) -> bool {
// Get the permissions granted to the bot in this community
let Some(granted_to_bot) = state.data.get_bot_permissions(&args.bot.user_id) else {
return false;
Expand All @@ -84,5 +84,5 @@ fn is_bot_permitted_to_execute_command(args: &Args, state: &RuntimeState) -> boo
// Get the permissions required to execute the given action
let permissions_required = args.action.permissions_required();

can_execute_bot_command(&permissions_required, granted_to_bot, &granted_to_user)
can_bot_execute_action(&permissions_required, granted_to_bot, &granted_to_user)
}
1 change: 1 addition & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Add optional `placeholder` field to `SlashCommandSchema` ([#7172](https://github.com/open-chat-labs/open-chat/pull/7172))
- Introduce `StableMemoryMap` trait to simplify storing in stable memory ([#7176](https://github.com/open-chat-labs/open-chat/pull/7176))
- Use typed command in `BotCommandClaims` ([#7113](https://github.com/open-chat-labs/open-chat/pull/7113))

## [[2.0.1547](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1547-local_user_index)] - 2025-01-06

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod c2c_notify_user_events;
pub mod c2c_notify_user_index_events;
pub mod c2c_push_wasm_chunk;
pub mod c2c_upgrade_user_canister_wasm;
pub mod execute_bot_command;
pub mod execute_bot_action;
pub mod invite_users_to_channel;
pub mod invite_users_to_community;
pub mod invite_users_to_group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn accept_if_valid(state: &RuntimeState) {
| "join_community"
| "join_group"
| "report_message_v2" => state.is_caller_openchat_user(),
"register_user" | "execute_bot_command" => true,
"register_user" | "execute_bot_action" => true,
_ => false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::rngs::StdRng;
use rand::SeedableRng;
use serde::Serialize;
use types::{
AccessTokenType, BotCommandClaims, ChannelId, Chat, ChatId, CheckAccessTokenType, CheckBotCommandArgs, CommunityId,
AccessTokenType, BotCommandClaims, ChannelId, Chat, ChatId, CheckAccessTokenBotCommand, CheckAccessTokenType, CommunityId,
JoinOrEndVideoCallClaims, StartVideoCallClaims, UserId,
};

Expand Down Expand Up @@ -69,9 +69,7 @@ async fn access_token(args: Args) -> Response {
chat: bc.chat.into(),
thread_root_message_index: bc.thread_root_message_index,
message_id: bc.message_id,
command_name: bc.command_name,
command_args: bc.command_args,
command_text: bc.command_text,
command: bc.command,
bot_api_gateway: state.env.canister_id(),
};
build_token(token_type_name, custom_claims, state)
Expand Down Expand Up @@ -105,23 +103,23 @@ fn prepare(args: &Args, state: &RuntimeState) -> Result<PrepareResult, Response>
}
AccessTokenType::JoinVideoCall => CheckAccessTokenType::JoinVideoCall,
AccessTokenType::MarkVideoCallAsEnded => CheckAccessTokenType::MarkVideoCallAsEnded,
AccessTokenType::BotCommand(cmd) => {
AccessTokenType::BotCommand(access_token) => {
let Some(permissions) = state
.data
.bots
.get(&cmd.bot)
.and_then(|b| b.commands.iter().find(|c| c.name == cmd.command_name))
.get(&access_token.bot)
.and_then(|b| b.commands.iter().find(|c| c.name == access_token.command.name))
.map(|c| c.permissions.clone())
else {
return Err(Response::NotAuthorized);
};

CheckAccessTokenType::BotCommand(CheckBotCommandArgs {
user_id: cmd.user_id,
bot: cmd.bot,
chat: cmd.chat,
thread_root_message_index: cmd.thread_root_message_index,
message_id: cmd.message_id,
CheckAccessTokenType::BotCommand(CheckAccessTokenBotCommand {
user_id: access_token.user_id,
bot: access_token.bot,
chat: access_token.chat,
thread_root_message_index: access_token.thread_root_message_index,
message_id: access_token.message_id,
permissions,
})
}
Expand Down
Loading
Loading