Skip to content

Commit

Permalink
Merge pull request #19 from Nabhag8848/feat/comment-on-page
Browse files Browse the repository at this point in the history
[Feat] Comment on Notion Page
  • Loading branch information
samad-yar-khan authored Aug 15, 2023
2 parents 3f8374a + 6041c78 commit d50d750
Show file tree
Hide file tree
Showing 26 changed files with 1,868 additions and 21 deletions.
37 changes: 36 additions & 1 deletion NotionApp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
IAppAccessors,
IAppInstallationContext, IConfigurationExtend, IEnvironmentRead,
IAppInstallationContext,
IConfigurationExtend,
IEnvironmentRead,
IHttp,
ILogger,
IModify,
Expand All @@ -22,6 +24,7 @@ import { ElementBuilder } from "./src/lib/ElementBuilder";
import { BlockBuilder } from "./src/lib/BlockBuilder";
import {
IUIKitResponse,
UIKitActionButtonInteractionContext,
UIKitBlockInteractionContext,
UIKitViewCloseInteractionContext,
UIKitViewSubmitInteractionContext,
Expand All @@ -31,6 +34,12 @@ import { ExecuteViewClosedHandler } from "./src/handlers/ExecuteViewClosedHandle
import { ExecuteViewSubmitHandler } from "./src/handlers/ExecuteViewSubmitHandler";
import { ExecuteBlockActionHandler } from "./src/handlers/ExecuteBlockActionHandler";
import { sendHelperMessageOnInstall } from "./src/helper/message";
import {
IUIActionButtonDescriptor,
UIActionButtonContext,
} from "@rocket.chat/apps-engine/definition/ui";
import { ActionButton } from "./enum/modals/common/ActionButtons";
import { ExecuteActionButtonHandler } from "./src/handlers/ExecuteActionButtonHandler";

export class NotionApp extends App {
private oAuth2Client: OAuth2Client;
Expand Down Expand Up @@ -64,6 +73,14 @@ export class NotionApp extends App {
this.NotionSdk = new NotionSDK(this.getAccessors().http);
this.elementBuilder = new ElementBuilder(this.getID());
this.blockBuilder = new BlockBuilder(this.getID());

const commentOnPagesButton: IUIActionButtonDescriptor = {
actionId: ActionButton.COMMENT_ON_PAGES_MESSAGE_BOX_ACTION,
labelI18n: ActionButton.COMMENT_ON_PAGES_MESSAGE_BOX_ACTION_LABEL,
context: UIActionButtonContext.MESSAGE_BOX_ACTION,
};

configurationExtend.ui.registerButton(commentOnPagesButton);
}

public getOAuth2Client(): OAuth2Client {
Expand Down Expand Up @@ -146,4 +163,22 @@ export class NotionApp extends App {
return;
}

public async executeActionButtonHandler(
context: UIKitActionButtonInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<IUIKitResponse> {
const handler = new ExecuteActionButtonHandler(
this,
read,
http,
persistence,
modify,
context
);

return await handler.handleActions();
}
}
37 changes: 36 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,40 @@
"nameSlug": "notion",
"classFile": "NotionApp.ts",
"description": "Integrating Notion With Rocket.Chat",
"implements": []
"implements": [],
"permissions": [
{
"name": "ui.registerButtons"
},
{
"name": "api"
},
{
"name": "slashcommand"
},
{
"name": "server-setting.read"
},
{
"name": "room.read"
},
{
"name": "persistence"
},
{
"name": "ui.interact"
},
{
"name": "networking"
},
{
"name": "message.write"
},
{
"name": "user.read"
},
{
"name": "room.write"
}
]
}
2 changes: 1 addition & 1 deletion definition/authorization/IOAuth2Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface INotionOwner {
user: INotionUser;
}

interface INotionUser {
export interface INotionUser {
object: NotionOwnerType.USER;
id: string;
name: string | null;
Expand Down
55 changes: 53 additions & 2 deletions definition/lib/INotion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IHttp } from "@rocket.chat/apps-engine/definition/accessors";
import { URL } from "url";
import { ITokenInfo } from "../authorization/IOAuth2Storage";
import { INotionUser, ITokenInfo } from "../authorization/IOAuth2Storage";
import { ClientError, Error } from "../../errors/Error";
import { NotionObjectTypes } from "../../enum/Notion";
import { NotionObjectTypes, NotionOwnerType } from "../../enum/Notion";
import { RichText } from "@tryfabric/martian/build/src/notion";

export interface INotion {
baseUrl: string;
Expand All @@ -22,6 +23,22 @@ export interface INotionSDK extends INotion {
token: string,
data: object
): Promise<INotionDatabase | Error>;
retrieveCommentsOnpage(
pageId: string,
token: string
): Promise<Array<ICommentInfo> | Error>;
retrieveUser(
userId: string,
token: string
): Promise<INotionUser | INotionUserBot | Error>;
retrieveAllUsers(
token: string
): Promise<Array<INotionUser | INotionUserBot> | Error>;
createCommentOnPage(
tokenInfo: ITokenInfo,
pageId: string,
comment: string
): Promise<ICommentInfo | Error>;
}

export interface IParentPage {
Expand All @@ -37,3 +54,37 @@ export interface INotionDatabase {
name: string;
link: string;
}

export interface ICommentInfo {
comment: string;
user: INotionUser | INotionUserBot;
created_time: string;
}

export interface ICommentObject {
object: NotionObjectTypes.COMMENT;
id: string;
parent: IParentPage;
discussion_id: string;
created_time: string;
last_edited_time: string;
created_by: Pick<INotionUser, "object" | "id">;
rich_text: Array<RichText>;
}

export interface INotionUserBot {
object: NotionOwnerType.USER;
id: string;
name: string | null;
avatar_url: string | null;
type: NotionOwnerType.BOT;
bot: INotionBot | {};
}

interface INotionBot {
owner: {
type: NotionObjectTypes.WORKSPACE;
workspace: boolean;
};
workspace_name: string;
}
1 change: 1 addition & 0 deletions enum/CommandParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum CommandParam {
DISCONNECT = "disconnect",
CREATE = "create",
HELP = "help",
COMMENT = "comment",
}

export enum SubCommandParam {
Expand Down
6 changes: 6 additions & 0 deletions enum/Notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum NotionOwnerType {
USER = "user",
PERSON = "person",
BOT = "bot",
ME = "me",
}

export enum NotionApi {
Expand All @@ -16,6 +17,8 @@ export enum NotionApi {
CONTENT_TYPE = "application/json",
SEARCH = `https://api.notion.com/v1/search`,
CREATE_DATABASE = `https://api.notion.com/v1/databases`,
COMMENTS = `https://api.notion.com/v1/comments`,
USERS = `https://api.notion.com/v1/users`,
}

export enum Notion {
Expand All @@ -32,4 +35,7 @@ export enum NotionObjectTypes {
FORMAT = "format",
EXPRESSION = "expression",
UNTITLED = "Untitled",
COMMENT = "comment",
PARENT = "parent",
MENTION = "mention",
}
1 change: 1 addition & 0 deletions enum/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Messages {
HELPER_COMMANDS = `• use \`/notion connect\` to connect your workspace
• use \`/notion disconnect\` to disconnect workspace
• use \`/notion comment\` to comment on notion page
• use \`/notion create database\` to create database
`,
HELPER_TEXT = `:wave: Need some help with \`/notion\`?`,
Expand Down
16 changes: 16 additions & 0 deletions enum/modals/CommentPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum CommentPage {
VIEW_ID = "comment-on-page-view-id",
TITLE = "Comment on Page",
SUBMIT_BUTTON_TEXT = "Comment On Page",
CLOSE_BUTTON_TEXT = "Close",
COMMENT_ON_PAGE_SUBMIT_ACTION = "comment-on-page-submit-action-id",
COMMENT_ON_PAGE_SUBMIT_BLOCK = "comment-on-page-submit-block-id",
COMMENT_ON_PAGE_CLOSE_ACTION = "comment-on-page-close-action-id",
COMMENT_ON_PAGE_CLOSE_BLOCK = "comment-on-page-close-block-id",
COMMENT_INPUT_PLACEHOLDER = "Add a comment...",
COMMENT_INPUT_LABEL = "Enter your Comment *",
COMMENT_INPUT_ACTION = "comment-on-page-input-action-id",
COMMENT_INPUT_BLOCK = "comment-on-page-input-block-id",
REFRESH_OPTION_TEXT = "Refresh For New Comments",
REFRESH_OPTION_VALUE = "refresh-option-value",
}
4 changes: 4 additions & 0 deletions enum/modals/common/ActionButtons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ActionButton {
COMMENT_ON_PAGES_MESSAGE_BOX_ACTION = "comment-on-pages-message-box-action",
COMMENT_ON_PAGES_MESSAGE_BOX_ACTION_LABEL = "CommentOnPagesLabel",
}
1 change: 1 addition & 0 deletions enum/modals/common/Modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export enum Modals {
OPTIONS = "options",
MISSING = "missing",
VIEWERROR = "viewError",
DATA = "data",
}
3 changes: 2 additions & 1 deletion enum/modals/common/SearchPageComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export enum SearchPage {
PLACEHOLDER = "Select a Page",
BLOCK_ID = "search-page-component-block-id",
ACTION_ID = "search-page-component-action-id",
LABEL = "Search For Page *"
LABEL = "Search For Page *",
SEARCH_COMMENT_ACTION_ID = "search-page-component-search-comment-action-id",
}
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"ClientSecretPlaceholder": "Shhh! This is super secret",
"CredentialsSettings": "Authorization Settings",
"NotionCommandParams": "connect | disconnect | workspace | create | schema | comment",
"NotionCommandDescription": "Create Notion pages and database from Rocket.Chat"
"NotionCommandDescription": "Create Notion pages and database from Rocket.Chat",
"CommentOnPagesLabel": "💬 Comment on Page"
}
Loading

0 comments on commit d50d750

Please sign in to comment.