Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Copy link
Copy Markdown
Collaborator

@Nabhag8848 Nabhag8848 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • oops, i believe you removed from documentation which is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add the emojis in the documentation?

Copy link
Copy Markdown
Collaborator

@Nabhag8848 Nabhag8848 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, revert changes of docs.

Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ Here are some links to examples and documentation:
[issues-shield]: https://img.shields.io/github/issues/RocketChat/Apps.Notion?style=for-the-badge
[issues-url]: https://github.com/RocketChat/Apps.Notion/issues
[license-shield]: https://img.shields.io/github/license/RocketChat/Apps.Notion?style=for-the-badge
[license-url]: https://github.com/RocketChat/Apps.Notion/blob/master/LICENSE.txt
[license-url]: https://github.com/RocketChat/Apps.Notion/blob/master/LICENSE.txt
6 changes: 3 additions & 3 deletions enum/OAuth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export enum OAuth2Locator {
export enum OAuth2Content {
success = "https://github-production-user-asset-6210df.s3.amazonaws.com/65061890/243671111-9964efff-3b23-4223-aadd-5f4be441037c.svg",
failed = "https://open.rocket.chat/assets/logo.png",
NOT_CONNECTED_MESSAGE = `👋 You are not connected to **Workspace**!`,
NOT_CONNECTED_MESSAGE_WITH_INFO = `👋 Connect to workspace to access \`pages\` & \`database\``,
NOT_CONNECTED_MESSAGE = `You are not connected to **Workspace**!`,
NOT_CONNECTED_MESSAGE_WITH_INFO = `Connect to workspace to access \`pages\` & \`database\``,
CONNECT_TO_WORKSPACE = "Connect to Workspace",
CREDENTIALS_MISSING_USER = `🚫 Something Went Wrong, Please Contact the Admin!`,
CREDENTIALS_MISSING_USER = `Something Went Wrong, Please Contact the Admin!`,
CREDENTIALS_MISSING_ADMIN = `Please Configure the App and Ensure the \`SiteUrl\` is correct in the Server Settings.
\xa0\xa0• Go to **NotionApp** Settings and add \`ClientId\` and \`ClientSecret\` Generated from a Notion Public Integration
`,
Expand Down
20 changes: 10 additions & 10 deletions enum/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ export enum Messages {
• use \`/notion share\` to share pages

`,
HELPER_TEXT = `:wave: Need some help with \`/notion\`?`,
HELPER_TEXT = `Need some help with \`/notion\`?`,
}

export enum OnInstallContent {
PREVIEW_TITLE = "[**📖 Notion App**](https://github.com/RocketChat/Apps.Notion/)",
PREVIEW_DESCRIPTION = "**🙌 Installed and Rollin' on your Server!**",
PREVIEW_CONTEXT = "[**🤝 Support's Page**](https://github.com/RocketChat/Apps.Notion/issues)",
PREVIEW_TITLE = "[**Notion App**](https://github.com/RocketChat/Apps.Notion/)",
PREVIEW_DESCRIPTION = "**Installed and Rollin' on your Server!**",
PREVIEW_CONTEXT = "[**Support's Page**](https://github.com/RocketChat/Apps.Notion/issues)",
PREVIEW_IMAGE = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Notion-logo.svg",
WELCOMING_MESSAGE = `🔧 Setting up the Notion App is a breeze! Create a [**Notion Public Integration**](https://developers.notion.com/docs/authorization#how-to-make-an-integration-public) and Just head over to the App Settings, Provide your credentials.
🎉 You're all set to experience the seamless integration of Notion and RocketChat.
Need some help getting started? Just type \`/notion help\` to access our comprehensive command list.
💌 We love hearing from you! If you have any suggestions, questions, or just want to share your thoughts, simply tap on the **Support's Page** in Preview.
🌟 Let's streamline your productivity and collaboration together. Enjoy the journey!
WELCOMING_MESSAGE = `Setting up the Notion App is a breeze! Create a [**Notion Public Integration**](https://developers.notion.com/docs/authorization#how-to-make-an-integration-public) and Just head over to the App Settings, Provide your credentials.
You're all set to experience the seamless integration of Notion and RocketChat.
Need some help getting started? Just type \`/notion help\` to access our comprehensive command list.
We love hearing from you! If you have any suggestions, questions, or just want to share your thoughts, simply tap on the **Support's Page** in Preview.
Let's streamline your productivity and collaboration together. Enjoy the journey!

Thanks for choosing \`Notion App\`
`,
WELCOME_TEXT = `Welcome to **Notion App** in RocketChat! 🙌`,
WELCOME_TEXT = `Welcome to **Notion App** in RocketChat! `,
}
6 changes: 3 additions & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"CredentialsSettings": "Authorization Settings",
"NotionCommandParams": "connect | disconnect | workspace | create | schema | comment",
"NotionCommandDescription": "Create Notion pages and database from Rocket.Chat",
"CommentOnPagesLabel": "💬 Comment on Page",
"SendToPageLabel": "📝 Send to Page",
"SendToNewPageLabel": "📢 Send to New Page"
"CommentOnPagesLabel": "Comment on Page",
"SendToPageLabel": "Send to Page",
"SendToNewPageLabel": "Send to New Page"
}
4 changes: 2 additions & 2 deletions src/authorization/OAuth2Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class OAuth2Client implements IOAuth2Client {
return;
}

const message = `Hey **${sender.username}**!👋 Connect your Notion Workspace`;
const message = `Hey **${sender.username}**! Connect your Notion Workspace`;
const blocks = await getConnectBlock(
this.app,
message,
Expand Down Expand Up @@ -66,7 +66,7 @@ export class OAuth2Client implements IOAuth2Client {

if (tokenInfo) {
await oAuthStorage.disconnectUserFromCurrentWorkspace(userId);
const message = `👋 You are disconnected from the Workspace **${tokenInfo.workspace_name}**`;
const message = `You are disconnected from the Workspace **${tokenInfo.workspace_name}**`;
await sendNotification(read, modify, sender, room, { message });
return;
}
Expand Down
40 changes: 24 additions & 16 deletions src/handlers/ExecuteViewSubmitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ export class ExecuteViewSubmitHandler {

if (response instanceof Error) {
this.app.getLogger().error(response);
message = `🚫 Something went wrong while creating Database in **${workspace_name}**.`;
message = `Something went wrong while creating Database in **${workspace_name}**.`;

await sendNotification(this.read, this.modify, user, room, {
message: message,
});
} else {
const name: string = response.name;
const link: string = response.link;
message = `Your Database [**${name}**](${link}) is created successfully in **${workspace_name}**.`;
message = `Your Database [**${name}**](${link}) is created successfully in **${workspace_name}**.`;

await sendNotificationWithAttachments(
this.read,
Expand Down Expand Up @@ -341,6 +341,7 @@ export class ExecuteViewSubmitHandler {
const parentType: string = parent.type;

if (parentType.includes(NotionObjectTypes.PAGE_ID)) {

return this.handleCreationOfPage(
tokenInfo,
room,
Expand All @@ -349,7 +350,7 @@ export class ExecuteViewSubmitHandler {
Objects as IPage
);
}

return this.handleCreationOfRecord(
tokenInfo,
room,
Expand Down Expand Up @@ -384,10 +385,10 @@ export class ExecuteViewSubmitHandler {

if (createdPage instanceof Error) {
this.app.getLogger().error(createdPage.message);
message = `🚫 Something went wrong while creating page in **${workspace_name}**.`;
message = `Something went wrong while creating page in **${workspace_name}**.`;
} else {
const { name, link, title, pageId } = createdPage;
message = `Your Page [**${title}**](${link}) is created successfully as a subpage in **${name}**.`;
message = `Your Page [**${title}**](${link}) is created successfully as a subpage in **${name}**.`;

const preserveMessage = await modalInteraction.getInputElementState(
ActionButton.SEND_TO_NEW_PAGE_MESSAGE_ACTION
Expand All @@ -410,7 +411,7 @@ export class ExecuteViewSubmitHandler {

if (appendBlock instanceof Error) {
this.app.getLogger().error(appendBlock.message);
message = `🚫 Something went wrong while appending message in **${workspace_name}**.`;
message = `Something went wrong while appending message in **${workspace_name}**.`;
await sendNotification(this.read, this.modify, user, room, {
message,
});
Expand All @@ -430,7 +431,7 @@ export class ExecuteViewSubmitHandler {
)) as ICredential;

const messageLink = `${siteUrl}/${urlPath}/${displayName}?msg=${id}`;
const preserveText = `📝 Created New Page [**${title}**](${link}) and Preserved Following [Message](${messageLink}) `;
const preserveText = `Created New Page [**${title}**](${link}) and Preserved Following [Message](${messageLink}) `;

await sendMessage(
this.read,
Expand Down Expand Up @@ -463,6 +464,13 @@ export class ExecuteViewSubmitHandler {
const { NotionSdk } = this.app.getUtils();
const { access_token, workspace_name, owner } = tokenInfo;
const username = owner.user.name;
const newDatabase = {
...database,
info: {
name: database.info.name.replace("📚 ",""),
link: database.info.link,
},
}
Copy link
Copy Markdown
Collaborator

@Nabhag8848 Nabhag8848 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, you overriding this due to when sending message to channel it was showing 📚. can't directly we can have const databasename = info.name.replace("📚",""); in line 504. mention below. so we don't need to have this newDatabase object

Suggested change
const newDatabase = {
...database,
info: {
name: database.info.name.replace("📚 ",""),
link: database.info.link,
},
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is better. I am making the changes.


const properties = (await modalInteraction.getInputElementState(
SearchPageAndDatabase.ACTION_ID
Expand All @@ -479,20 +487,20 @@ export class ExecuteViewSubmitHandler {

const createdRecord = await NotionSdk.createRecord(
access_token,
database,
newDatabase,
data
);

let message: string;

if (createdRecord instanceof Error) {
this.app.getLogger().error(createdRecord.message);
message = `🚫 Something went wrong while creating record in **${workspace_name}**.`;
message = `Something went wrong while creating record in **${workspace_name}**.`;
await sendNotification(this.read, this.modify, user, room, {
message,
});
} else {
const { info } = database;
const { info } = newDatabase;
const databasename = info.name;
Copy link
Copy Markdown
Collaborator

@Nabhag8848 Nabhag8848 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, as i mentioned above.

Suggested change
const databasename = info.name;
const databasename = info.name.replace("📚 ","");

const databaselink = info.link;
const title: string =
Expand All @@ -501,7 +509,7 @@ export class ExecuteViewSubmitHandler {
];
const { fields, url, pageId } = createdRecord;

message = `Created [**${title}**](${url}) in [**${databasename}**](${databaselink})`;
message = `Created [**${title}**](${url}) in [**${databasename}**](${databaselink})`;

const messageId = await sendMessageWithAttachments(
this.read,
Expand Down Expand Up @@ -533,7 +541,7 @@ export class ExecuteViewSubmitHandler {

if (appendBlock instanceof Error) {
this.app.getLogger().error(appendBlock.message);
message = `🚫 Something went wrong while appending message in **${workspace_name}**.`;
message = `Something went wrong while appending message in **${workspace_name}**.`;
await sendNotification(this.read, this.modify, user, room, {
message,
});
Expand All @@ -554,7 +562,7 @@ export class ExecuteViewSubmitHandler {
)) as ICredential;

const messageLink = `${siteUrl}/${urlPath}/${displayName}?msg=${id}`;
const preserveText = `📝 Created [**${title}**](${url}) Page and Preserved Following [Message](${messageLink}) `;
const preserveText = `Created [**${title}**](${url}) Page and Preserved Following [Message](${messageLink}) `;

await sendMessage(
this.read,
Expand Down Expand Up @@ -814,7 +822,7 @@ export class ExecuteViewSubmitHandler {

const { name, parent, url } = pageInfo;

const message = `Sharing [**${name}**](${url}) from **${workspace_name}**`;
const message = `Sharing [**${name}**](${url}) from **${workspace_name}**`;

await sendMessage(this.read, this.modify, user, room, {
message,
Expand Down Expand Up @@ -878,7 +886,7 @@ export class ExecuteViewSubmitHandler {

if (appendBlock instanceof Error) {
this.app.getLogger().error(appendBlock.message);
const message = `🚫 Something went wrong while appending message in **${workspace_name}**.`;
const message = `Something went wrong while appending message in **${workspace_name}**.`;
await sendNotification(this.read, this.modify, user, room, {
message,
});
Expand Down Expand Up @@ -913,7 +921,7 @@ export class ExecuteViewSubmitHandler {
)) as ICredential;

const messageLink = `${siteUrl}/${urlPath}/${displayName}?msg=${id}`;
const preserveText = `📝 Preserved Following [Message](${messageLink}) in [**${name}**](${url}) `;
const preserveText = `Preserved Following [Message](${messageLink}) in [**${name}**](${url}) `;

await sendMessage(
this.read,
Expand Down
4 changes: 2 additions & 2 deletions src/helper/getConnectLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function getConnectPreview(
: undefined;
const thumb = workspace_icon_url ? { url: workspace_icon_url } : undefined;
const title = [
`**📚 [**${workspace_name}**](${Notion.WEBSITE_URL})**`,
"**👋 Connected to Workspace**",
`** [**${workspace_name}**](${Notion.WEBSITE_URL})**`,
"**Connected to Workspace**",
];
const description = [""];
const avatarElement = elementBuilder.addImage({
Expand Down
5 changes: 3 additions & 2 deletions src/helper/getSelectDatabaseLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function getSelectDatabaseLayout(

const database_name = properties.name;
const database_url = properties.link;
const databaseNameWithoutEmoji = database_name.replace("📚 ", "")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly replace emoji in database_name variable to avoid creating new variable.

line 16: const database_name = properties.name.replace("📚 ", "");
Suggested change
const databaseNameWithoutEmoji = database_name.replace("📚 ", "")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad


const elementBuilder = new ElementBuilder(appId);
const blockBuilder = new BlockBuilder(appId);
Expand All @@ -26,8 +27,8 @@ export function getSelectDatabaseLayout(
: undefined;
const thumb = workspace_icon_url ? { url: workspace_icon_url } : undefined;
const title = [
`**📋 Database Name**`,
`[**${database_name}**](${database_url})`,
`**Database Name**`,
`[**${databaseNameWithoutEmoji}**](${database_url})`,
];
const description = [""];
const avatarElement = elementBuilder.addImage({
Expand Down
32 changes: 18 additions & 14 deletions src/lib/NotionSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class NotionSDK implements INotionSDK {

const result: Array<IPage> = [];
results.forEach(async (item) => {
const pageObject = await this.getPageObjectFromResults(item);
const pageObject = await this.getPageObjectFromResults(item, false);
if (pageObject) {
result.push(pageObject);
}
Expand All @@ -132,7 +132,7 @@ export class NotionSDK implements INotionSDK {
}
}

private async getPageObjectFromResults(item): Promise<IPage | null> {
private async getPageObjectFromResults(item, emoji:boolean=false): Promise<IPage | null> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are making changes in this file with suggestions, make a indentation with other methods too which has default value of emoji.

Suggested change
private async getPageObjectFromResults(item, emoji:boolean=false): Promise<IPage | null> {
private async getPageObjectFromResults(item, emoji:boolean = false): Promise<IPage | null> {

const typesWithTitleProperty = [
NotionObjectTypes.WORKSPACE.toString(),
NotionObjectTypes.PAGE_ID.toString(),
Expand All @@ -145,7 +145,7 @@ export class NotionSDK implements INotionSDK {
const pageName: string =
properties.title.title[0]?.text?.content ||
NotionObjectTypes.UNTITLED;
return this.returnPage(pageName, pageId);
return this.returnPage(pageName, pageId, emoji);
}

// title property either be at first or last position
Expand All @@ -161,7 +161,7 @@ export class NotionSDK implements INotionSDK {
const name: string =
properties[firstColumn].title[0]?.text?.content ||
NotionObjectTypes.UNTITLED;
return this.returnPage(name, pageId);
return this.returnPage(name, pageId, emoji);
}

//title at last position and has subpage
Expand All @@ -172,15 +172,15 @@ export class NotionSDK implements INotionSDK {
const name: string =
properties[lastColumn].title[0]?.text?.content ||
NotionObjectTypes.UNTITLED;
return this.returnPage(name, pageId);
return this.returnPage(name, pageId, emoji);
}

return null;
}

private returnPage(name: string, page_id: string): IPage {
private returnPage(name: string, page_id: string, emoji: boolean=false): IPage {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private returnPage(name: string, page_id: string, emoji: boolean=false): IPage {
private returnPage(name: string, page_id: string, emoji: boolean = false): IPage {

return {
name: `📄 ${name}`,
name: `${emoji ? "📄" : ""} ${name}`,
parent: {
type: NotionObjectTypes.PAGE_ID,
page_id,
Expand Down Expand Up @@ -520,15 +520,16 @@ export class NotionSDK implements INotionSDK {
const objectType: string = item?.[NotionObjectTypes.OBJECT];
if (objectType.includes(NotionObjectTypes.PAGE)) {
const pageObject = await this.getPageObjectFromResults(
item
item,
true
);

if (pageObject) {
result.push(pageObject);
}
} else {
const databaseObject =
await this.getDatabaseObjectFromResults(item);
await this.getDatabaseObjectFromResults(item, true);

result.push(databaseObject);
}
Expand All @@ -540,7 +541,7 @@ export class NotionSDK implements INotionSDK {
}
}

private async getDatabaseObjectFromResults(item): Promise<IDatabase> {
private async getDatabaseObjectFromResults(item, emoji:boolean=false): Promise<IDatabase> {
const databaseNameTitleObject = item?.[NotionObjectTypes.TITLE];
const name: string = databaseNameTitleObject.length
? databaseNameTitleObject[0]?.plain_text
Expand All @@ -549,7 +550,7 @@ export class NotionSDK implements INotionSDK {

return {
info: {
name: `📚 ${name}`,
name: `${emoji ? "📚":""} ${name}`,
link: item?.url,
},
parent: {
Expand All @@ -567,6 +568,7 @@ export class NotionSDK implements INotionSDK {
try {
const { name, parent } = page;
const { title } = prop;
const nameWithoutEmoji = name.replace("📄", "");
Copy link
Copy Markdown
Collaborator

@Nabhag8848 Nabhag8848 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid long variable name here, make neccessary changes which would affect this below.

Suggested change
const { name, parent } = page;
const { title } = prop;
const nameWithoutEmoji = name.replace("📄", "");
const { parent } = page;
const { title } = prop;
const name = page.name.replace("📄", "");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki


const data = {
parent,
Expand Down Expand Up @@ -597,7 +599,7 @@ export class NotionSDK implements INotionSDK {

let result: INotionPage = {
link: response?.data?.url,
name,
name: nameWithoutEmoji,
title,
};

Expand Down Expand Up @@ -989,7 +991,8 @@ export class NotionSDK implements INotionSDK {

const pageInfo = response.data;
const page = (await this.getPageObjectFromResults(
pageInfo
pageInfo,
false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Previously we made a emoji param default value false so that we don't need to pass it when its false, remove from every calls where it is false. there are at several other places.
Suggested change
false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki making the changes

)) as IPage;
const url: string = pageInfo?.url;

Expand Down Expand Up @@ -1089,7 +1092,8 @@ export class NotionSDK implements INotionSDK {
results.forEach(async (item) => {
const objectType: string = item?.[NotionObjectTypes.OBJECT];
const databaseObject = await this.getDatabaseObjectFromResults(
item
item,
false
);

result.push(databaseObject);
Expand Down