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

Modify message #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
29 changes: 12 additions & 17 deletions github/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { IssueDisplayModal } from "../modals/IssueDisplayModal";
import { IGitHubIssue } from "../definitions/githubIssue";
import { BodyMarkdownRenderer } from "../processors/bodyMarkdowmRenderer";
import { CreateIssueStatsBar } from "../lib/CreateIssueStatsBar";
import { IMessageAttachment } from "@rocket.chat/apps-engine/definition/messages";

export class ExecuteBlockActionHandler {

Expand Down Expand Up @@ -291,7 +292,10 @@ export class ExecuteBlockActionHandler {
}
case ModalsEnum.SHARE_PROFILE_EXEC : {
let {user, room} = context.getInteractionData();
const block = this.modify.getCreator().getBlockBuilder();
const message=this.modify.getCreator().startMessage();
let text:string="";
let attachment:Array<IMessageAttachment>=[{}];
const block=this.modify.getCreator().getBlockBuilder();
let accessToken = await getAccessTokenForUser(this.read, user ,this.app.oauth2Config) as IAuthData;
const userProfile = await getBasicUserInfo(this.http, accessToken.token);

Expand All @@ -310,25 +314,15 @@ export class ExecuteBlockActionHandler {
}

if (profileShareParams.includes('avatar')){
block.addImageBlock({
imageUrl : userProfile.avatar,
altText : "User Info"
})
Object.assign(attachment[0],{thumbnailUrl:userProfile.avatar});
}

profileShareParams.map((value) => {
if (value != 'contributionGraph' && value != 'avatar'){
block.addSectionBlock({
text : block.newPlainTextObject(value),
})
block.addContextBlock({
elements : [
block.newPlainTextObject(userProfile[value], true),
]
});
block.addDividerBlock();
text=text+`## ${value}\n${userProfile[value]}\n`
}
})
Object.assign(attachment[0],{text:text})

if (profileShareParams.includes('contributionGraph')){
block.addImageBlock({imageUrl : `https://activity-graph.herokuapp.com/graph?username=${userProfile.username}&bg_color=ffffff&color=708090&line=24292e&point=24292e`, altText: "Github Contribution Graph"})
Expand All @@ -337,16 +331,17 @@ export class ExecuteBlockActionHandler {

if(user?.id){
if(room?.id){
await sendMessage(this.modify, room!, user, `${userProfile.name}'s Github Profile`, block)
}else{
message.setRoom(room).setAttachments(attachment).setBlocks(block.getBlocks()).setSender(user);
await this.modify.getCreator().finish(message); }else{
let roomId = (
await getInteractionRoomData(
this.read.getPersistenceReader(),
user.id
)
).roomId;
room = await this.read.getRoomReader().getById(roomId) as IRoom;
await sendMessage(this.modify, room, user, `${userProfile.name}'s Github Profile`, block)
message.setRoom(room).setAttachments(attachment).setBlocks(block.getBlocks()).setSender(user);
await this.modify.getCreator().finish(message);
}
}

Expand Down