Skip to content

Commit

Permalink
Merge branch 'main' into expand-code
Browse files Browse the repository at this point in the history
  • Loading branch information
VipinDevelops authored Jun 27, 2023
2 parents cf1b0bb + 0e9b052 commit 6a5686c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
21 changes: 19 additions & 2 deletions github/GithubApp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IAppAccessors,
IAppInstallationContext,
IConfigurationExtend,
IHttp,
ILogger,
Expand Down Expand Up @@ -28,7 +29,11 @@ import {
} from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2";
import { createOAuth2Client } from "@rocket.chat/apps-engine/definition/oauth2/OAuth2";
import { createSectionBlock } from "./lib/blocks";
import { sendDirectMessage, sendNotification } from "./lib/message";
import {
sendDirectMessage,
sendDirectMessageOnInstall,
sendNotification,
} from "./lib/message";
import { OAuth2Client } from "@rocket.chat/apps-engine/server/oauth2/OAuth2Client";
import { deleteOathToken } from "./processors/deleteOAthToken";
import { ProcessorsEnum } from "./enum/Processors";
Expand Down Expand Up @@ -93,8 +98,10 @@ export class GithubApp extends App implements IPreMessageSentExtend {
},
};
let text = `GitHub Authentication Succesfull 🚀`;

let interactionData = await getInteractionRoomData(read.getPersistenceReader(), user.id);


if (token) {
// await registerAuthorizedUser(read, persistence, user);
await modify.getScheduler().scheduleOnce(deleteTokenTask);
Expand All @@ -104,12 +111,12 @@ export class GithubApp extends App implements IPreMessageSentExtend {
if (interactionData && interactionData.roomId) {
let roomId = interactionData.roomId as string;
let room = await read.getRoomReader().getById(roomId) as IRoom;

await clearInteractionRoomData(persistence, user.id);
await sendNotification(read, modify, user, room, text);
} else {
await sendDirectMessage(read, modify, user, text, persistence);
}

}
public oauth2ClientInstance: IOAuth2Client;
public oauth2Config: IOAuth2ClientOptions = {
Expand Down Expand Up @@ -225,4 +232,14 @@ export class GithubApp extends App implements IPreMessageSentExtend {
endpoints: [new githubWebHooks(this)],
});
}
public async onInstall(
context: IAppInstallationContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<void> {
const user = context.user;
await sendDirectMessageOnInstall(read, modify, user, persistence);
}
}
36 changes: 35 additions & 1 deletion github/lib/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,38 @@ export async function sendDirectMessage(
export function isUserHighHierarchy(user: IUser): boolean {
const clearanceList = ['admin', 'owner', 'moderator'];
return user.roles.some((role) => clearanceList.includes(role));
}
}

export async function sendDirectMessageOnInstall(
read: IRead,
modify: IModify,
user: IUser,
persistence: IPersistence
) {
if (user.roles.includes("admin")) {
const message = `
Hello **${user.name}!** Thank you for installing the **GitHub Rocket.Chat App**.
Here's some important information to get you started:
\xa0\xa0• **Quick and Easy Setup**: You can log in to GitHub with just one click using the built-in OAuth2 mechanism.
\xa0\xa0• **Stay Updated**: Subscribe to Repository Events to receive notifications about new issues, pull requests, and more.
\xa0\xa0• **Review and Merge Pull Requests**: You can conveniently review and merge pull requests directly from RocketChat Channels.
\xa0\xa0• **Create and Manage Issues**: Create new issues from RocketChat and easily search and share existing issues and pull requests using extensive filters.
\xa0\xa0• **Slash Commands**: Access the app using the slash commands \`/gh\` or \`/github\`.
To assist you further, use the power of \`/github help\` to unlock a world of enhanced teamwork
To unlock the full potential of the GitHub App, you need to set up a **GitHub OAuth App**. Follow these steps:
\xa0\xa0• Set up a GitHub OAuth2 App by following the instructions provided.
\xa0\xa0• Ensure the callback URL is set to your server's URL (Note: Remove any trailing '/' at the end of the hosted URL if authentication issues occur).
\xa0\xa0• Once the GitHub OAuth app is set up, access the GitHub Application Settings and enter the GitHub App OAuth Client Id and Client Secret.
We hope it enhances your collaboration and workflow. We would love to hear your feedback on your experience with the app.
Your feedback helps us improve and provide a better user experience. Please visit the link to [**provide your feedback**](https://github.com/RocketChat/Apps.Github22/issues)
Happy collaborating with \`GitHub\` and \`RocketChat\` :rocket:
`;
await sendDirectMessage(read, modify, user, message, persistence);
}
}

0 comments on commit 6a5686c

Please sign in to comment.