diff --git a/github/handlers/EventHandler.ts b/github/handlers/EventHandler.ts index 2d74cca..51eac1f 100644 --- a/github/handlers/EventHandler.ts +++ b/github/handlers/EventHandler.ts @@ -15,6 +15,7 @@ import { } from "../helpers/githubSDK"; import { sendNotification } from "../lib/message"; import { subscriptionsModal } from "../modals/subscriptionsModal"; +import { getGithubOauthBlock } from "../oath2/authentication"; import { getAccessTokenForUser } from "../persistance/auth"; import { Subscription } from "../persistance/subscriptions"; import { HandleInvalidRepoName } from "./HandleInvalidRepoName"; @@ -135,12 +136,16 @@ export async function SubscribeAllEvents( console.log("SubcommandError", error); } } else { + const user = context.getSender(); + const message = `Login to subscribe to repository events!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login to subscribe to repository events ! `/github login`" + message, + block ); } } @@ -254,12 +259,16 @@ export async function UnsubscribeAllEvents( console.log("SubcommandError", error); } } else { + const user = context.getSender(); + const message = `Login to unsubscribe from repository events!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login to subscribe to repository events ! `/github login`" + message, + block ); } } @@ -295,12 +304,16 @@ export async function ManageSubscriptions( console.log("Invalid Trigger ID !"); } } else { + const user = context.getSender(); + const message = `Login to manage repository events!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login to subscribe to repository events ! `/github login`" + message, + block ); } } diff --git a/github/handlers/HandleIssues.ts b/github/handlers/HandleIssues.ts index 8227c6e..3ada061 100644 --- a/github/handlers/HandleIssues.ts +++ b/github/handlers/HandleIssues.ts @@ -6,6 +6,8 @@ import { sendNotification } from "../lib/message"; import { NewIssueStarterModal } from "../modals/newIssueStarterModal"; import { getAccessTokenForUser } from "../persistance/auth"; import { GitHubIssuesStarterModal } from "../modals/getIssuesStarterModal"; +import { getGithubOauthBlock } from "../oath2/authentication"; +import { createSectionBlock } from "../lib/blocks"; export async function handleNewIssue( read: IRead, @@ -42,12 +44,16 @@ export async function handleNewIssue( console.log("invalid Trigger ID !"); } } else { + const user = context.getSender(); + const message = `Login to add a new issue!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login to subscribe to repository events ! `/github login`" + message, + block ); } } diff --git a/github/handlers/SearchHandler.ts b/github/handlers/SearchHandler.ts index b863818..42454eb 100644 --- a/github/handlers/SearchHandler.ts +++ b/github/handlers/SearchHandler.ts @@ -4,6 +4,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { GithubApp } from "../GithubApp"; import { sendNotification } from "../lib/message"; import { githubSearchModal } from "../modals/githubSearchModal"; +import { getGithubOauthBlock } from "../oath2/authentication"; import { getAccessTokenForUser } from "../persistance/auth"; export async function handleSearch( @@ -41,12 +42,16 @@ export async function handleSearch( console.log("invalid Trigger ID !"); } } else { + const user = context.getSender(); + const message = `Login to search issues!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login to subscribe to repository events ! `/github login`" + message, + block ); } } diff --git a/github/handlers/UserProfileHandler.ts b/github/handlers/UserProfileHandler.ts index 0c94295..2a4902b 100644 --- a/github/handlers/UserProfileHandler.ts +++ b/github/handlers/UserProfileHandler.ts @@ -3,8 +3,10 @@ import { IRoom } from "@rocket.chat/apps-engine/definition/rooms"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"; import { GithubApp } from "../GithubApp"; +import { createSectionBlock } from "../lib/blocks"; import { sendNotification } from "../lib/message"; import { userProfileModal } from "../modals/UserProfileModal"; +import { getGithubOauthBlock } from "../oath2/authentication"; import { getAccessTokenForUser } from "../persistance/auth"; export async function handleUserProfileRequest( @@ -40,12 +42,16 @@ export async function handleUserProfileRequest( ); } }else { + const user = context.getSender(); + const message = `Login to get your user info!`; + const block = await getGithubOauthBlock(app, user, modify, message); await sendNotification( read, modify, - context.getSender(), + user, room, - "Login is Mandatory for getting User Info ! `/github login`" + message, + block ) } diff --git a/github/oath2/authentication.ts b/github/oath2/authentication.ts index 4108fd2..c6fec42 100644 --- a/github/oath2/authentication.ts +++ b/github/oath2/authentication.ts @@ -18,6 +18,13 @@ export async function authorize( room: IRoom, persistence: IPersistence ): Promise { + const message = `Login to GitHub`; + const block = await getGithubOauthBlock(app, user, modify, message); + await storeInteractionRoomData(persistence,user.id,room.id); + await sendNotification(read, modify, user, room, message, block); +} + +export async function getGithubOauthBlock(app: GithubApp, user: IUser, modify: IModify, message: string) { const url = await app .getOauth2ClientInstance() .getUserAuthorizationUrl(user); @@ -26,8 +33,7 @@ export async function authorize( text: "GitHub Login", url: url.toString(), }; - const message = `Login to GitHub`; + const block = await createSectionBlock(modify, message, button); - await storeInteractionRoomData(persistence,user.id,room.id); - await sendNotification(read, modify, user, room, message, block); -} + return block; +} \ No newline at end of file