fix: slack linkback not poping up (#2099)

This commit is contained in:
Henit Chobisa
2025-01-03 14:38:34 +05:30
committed by GitHub
parent 3097794869
commit ff2b36dbeb
5 changed files with 65 additions and 67 deletions

View File

@@ -52,6 +52,7 @@ export type TBlockActionPayload = {
trigger_id: string;
message?: {
thread_ts: string;
text?: string;
};
response_url?: string;
actions: ISlackAction[];

View File

@@ -1,5 +1,5 @@
import { env } from "@/env";
import { ExCycle, ExIssue, ExProject, ExState, PlaneUser } from "@plane/sdk";
import { ExIssue, ExProject, ExState, PlaneUser } from "@plane/sdk";
import { formatTimestampToNaturalLanguage } from "../helpers/format-date";
import { ACTIONS, PLANE_PRIORITIES } from "../helpers/constants";
import { convertUnicodeToSlackEmoji } from "../helpers/emoji-converter";
@@ -9,10 +9,10 @@ export const createSlackLinkback = (
project: ExProject,
members: PlaneUser[],
state: ExState[],
cycles: ExCycle[],
issue: ExIssue
issue: ExIssue,
isSynced: boolean,
showLogo = false
) => {
const today = new Date().toISOString().split("T")[0];
const targetState = state.find((s) => s.id === issue.state);
const stateList = state.map((s) => ({
@@ -24,15 +24,6 @@ export const createSlackLinkback = (
value: `${issue.project}.${issue.id}.${s.id}`,
}));
const cycleList = cycles.map((c) => ({
text: {
type: "plain_text",
text: c.name,
emoji: true,
},
value: `${issue.project}.${issue.id}.${c.id}`,
}));
const priorityList = PLANE_PRIORITIES.map((p) => ({
text: {
type: "plain_text",
@@ -45,20 +36,22 @@ export const createSlackLinkback = (
// Create base blocks array
const blocks: any[] = [];
blocks.push({
type: "context",
elements: [
{
type: "image",
image_url: "https://res.cloudinary.com/ddglxo0l3/image/upload/v1732200793/xljpcpmftawmjkv4x61s.png",
alt_text: "Plane",
},
{
type: "mrkdwn",
text: `*Plane*`,
},
],
});
if (showLogo) {
blocks.push({
type: "context",
elements: [
{
type: "image",
image_url: "https://res.cloudinary.com/ddglxo0l3/image/upload/v1732200793/xljpcpmftawmjkv4x61s.png",
alt_text: "Plane",
},
{
type: "mrkdwn",
text: `*Plane*`,
},
],
});
}
blocks.push({
type: "section",
@@ -68,31 +61,13 @@ export const createSlackLinkback = (
},
});
// Only add description if it exists
// if (issue.description_stripped) {
// blocks.push({
// type: "rich_text",
// elements: [
// {
// type: "rich_text_preformatted",
// elements: [
// {
// type: "text",
// text: issue.description_stripped,
// },
// ],
// },
// ],
// });
// }
// Create context elements array with only non-empty values
const contextElements: any[] = [];
if (project.name) {
contextElements.push({
type: "mrkdwn",
text: `${project.logo_props ? convertUnicodeToSlackEmoji(project.logo_props.emoji.value) : ""} <${env.APP_BASE_URL}/${workspaceSlug}/projects/${issue.project}/issues|${project.name}>`,
text: `${project.logo_props && project.logo_props.emoji ? convertUnicodeToSlackEmoji(project.logo_props.emoji.value) : ""} <${env.APP_BASE_URL}/${workspaceSlug}/projects/${issue.project}/issues|${project.name}>`,
});
}
@@ -131,6 +106,23 @@ export const createSlackLinkback = (
});
}
if (isSynced) {
blocks.push({
type: "context",
elements: [
{
type: "image",
image_url: "https://res.cloudinary.com/ddglxo0l3/image/upload/v1732200793/xljpcpmftawmjkv4x61s.png",
alt_text: "Plane",
},
{
type: "mrkdwn",
text: `*Synced with Plane*`,
},
],
});
}
blocks.push({
type: "divider",
});

View File

@@ -131,6 +131,9 @@ async function handleCreateWebLinkAction(data: TBlockActionPayload) {
async function handleSwitchPriorityAction(data: TBlockActionPayload) {
if (data.actions[0].type !== "static_select") return;
const isThreadSync =
data.message && data.message.text && data.message.text.includes("Synced with Plane") ? true : false;
const selection = data.actions[0].selected_option;
if (!selection) return;
@@ -148,7 +151,6 @@ async function handleSwitchPriorityAction(data: TBlockActionPayload) {
const issue = await planeClient.issue.getIssue(workspaceConnection.workspaceSlug, projectId, issueId);
const project = await planeClient.project.getProject(workspaceConnection.workspaceSlug, projectId);
const states = await planeClient.state.list(workspaceConnection.workspaceSlug, projectId);
const cycles = await planeClient.cycles.list(workspaceConnection.workspaceSlug, projectId);
const members = await planeClient.users.list(workspaceConnection.workspaceSlug, projectId);
// Create updated linkback
@@ -157,8 +159,8 @@ async function handleSwitchPriorityAction(data: TBlockActionPayload) {
project,
members,
states.results,
cycles.results,
issue
issue,
isThreadSync
);
// Update the unfurl using response_url with proper Slack message format
@@ -233,6 +235,8 @@ async function handleProjectSelectAction(data: TBlockActionModalPayload) {
async function handleLinkbackStateChange(data: TBlockActionPayload) {
if (data.actions[0].type === "static_select") {
const isThreadSync =
data.message && data.message.text && data.message.text.includes("Synced with Plane") ? true : false;
const selection = data.actions[0].selected_option;
if (!selection) return;
@@ -253,7 +257,6 @@ async function handleLinkbackStateChange(data: TBlockActionPayload) {
const issue = await planeClient.issue.getIssue(workspaceConnection.workspaceSlug, projectId, issueId);
const project = await planeClient.project.getProject(workspaceConnection.workspaceSlug, projectId);
const states = await planeClient.state.list(workspaceConnection.workspaceSlug, projectId);
const cycles = await planeClient.cycles.list(workspaceConnection.workspaceSlug, projectId);
const members = await planeClient.users.list(workspaceConnection.workspaceSlug, projectId);
// Create updated linkback
@@ -262,8 +265,8 @@ async function handleLinkbackStateChange(data: TBlockActionPayload) {
project,
members,
states.results,
cycles.results,
issue
issue,
isThreadSync
);
// Update the unfurl using response_url with proper Slack message format

View File

@@ -1,13 +1,11 @@
import { SlackEventPayload, SlackLinkSharedEvent, UnfurlMap } from "@plane/etl/slack";
import { SlackEventPayload, UnfurlMap } from "@plane/etl/slack";
import { getConnectionDetails } from "../../helpers/connection-details";
import { getEntityConnectionByEntityId } from "@/db/query/connection";
import { extractPlaneResource } from "../../helpers/parse-plane-resources";
import { createSlackLinkback } from "../../views/issue-linkback";
import { convertUnicodeToSlackEmoji } from "../../helpers/emoji-converter";
import { createProjectLinkback } from "../../views/project-linkback";
import { createCycleLinkback } from "../../views/cycle-linkback";
import { createModuleLinkback } from "../../views/module-linkback";
import axios from "axios";
export const handleSlackEvent = async (data: SlackEventPayload) => {
switch (data.event.type) {
@@ -38,12 +36,17 @@ export const handleMessageEvent = async (data: SlackEventPayload) => {
const planeUser = members.find((member) => member.email === userInfo?.user.profile.email);
await planeClient.issueComment.create(workspaceConnection.workspaceSlug, eConnection.projectId ?? "", issueId ?? "", {
comment_html: `<p>${data.event.text}</p>`,
external_source: "SLACK_COMMENT",
external_id: data.event.event_ts,
created_by: planeUser?.id,
});
await planeClient.issueComment.create(
workspaceConnection.workspaceSlug,
eConnection.projectId ?? "",
issueId ?? "",
{
comment_html: `<p>${data.event.text}</p>`,
external_source: "SLACK_COMMENT",
external_id: data.event.event_ts,
created_by: planeUser?.id,
}
);
}
};
@@ -70,15 +73,15 @@ export const handleLinkSharedEvent = async (data: SlackEventPayload) => {
);
const states = await planeClient.state.list(workspaceConnection.workspaceSlug, issue.project);
const cycles = await planeClient.cycles.list(workspaceConnection.workspaceSlug, issue.project);
const linkBack = createSlackLinkback(
workspaceConnection.workspaceSlug,
project,
members,
states.results,
cycles.results,
issue
issue,
false,
true
);
unfurlMap[link.url] = linkBack;

View File

@@ -31,15 +31,14 @@ export const handleViewSubmission = async (data: TViewSubmissionPayload) => {
const project = await planeClient.project.getProject(workspaceConnection.workspaceSlug, parsedData.project);
const states = await planeClient.state.list(workspaceConnection.workspaceSlug, issue.project);
const cycles = await planeClient.cycles.list(workspaceConnection.workspaceSlug, issue.project);
const linkBack = createSlackLinkback(
workspaceConnection.workspaceSlug,
project,
members,
states.results,
cycles.results,
issue
issue,
parsedData.enableThreadSync || false
);
if (metadata.entityType === ENTITIES.ISSUE_SUBMISSION && metadata.entityPayload.type === "message_action") {