fix: slack urgent fix for posting
This commit is contained in:
parent
5bfb97e9a4
commit
7eeb1cb044
|
|
@ -137,6 +137,10 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
|
||||||
postDetails: PostDetails[],
|
postDetails: PostDetails[],
|
||||||
integration: Integration
|
integration: Integration
|
||||||
): Promise<PostResponse[]> {
|
): Promise<PostResponse[]> {
|
||||||
|
const [firstPost] = postDetails;
|
||||||
|
const channel = firstPost.settings.channel;
|
||||||
|
|
||||||
|
// Join the channel first
|
||||||
await fetch(`https://slack.com/api/conversations.join`, {
|
await fetch(`https://slack.com/api/conversations.join`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -144,48 +148,131 @@ export class SlackProvider extends SocialAbstract implements SocialProvider {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
channel: postDetails[0].settings.channel,
|
channel,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
let lastId = '';
|
// Post the main message
|
||||||
for (const post of postDetails) {
|
const { ts, channel: responseChannel } = await (
|
||||||
const { ts } = await (
|
await fetch(`https://slack.com/api/chat.postMessage`, {
|
||||||
await fetch(`https://slack.com/api/chat.postMessage`, {
|
method: 'POST',
|
||||||
method: 'POST',
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
channel,
|
||||||
|
username: integration.name,
|
||||||
|
icon_url: integration.picture,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: firstPost.message,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...(firstPost.media?.length
|
||||||
|
? firstPost.media.map((m) => ({
|
||||||
|
type: 'image',
|
||||||
|
image_url: m.path,
|
||||||
|
alt_text: '',
|
||||||
|
}))
|
||||||
|
: []),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
).json();
|
||||||
|
|
||||||
|
// Get permalink for the message
|
||||||
|
const { permalink } = await (
|
||||||
|
await fetch(
|
||||||
|
`https://slack.com/api/chat.getPermalink?channel=${responseChannel}&message_ts=${ts}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
}
|
||||||
channel: postDetails[0].settings.channel,
|
)
|
||||||
username: integration.name,
|
).json();
|
||||||
icon_url: integration.picture,
|
|
||||||
...(lastId ? { thread_ts: lastId } : {}),
|
return [
|
||||||
blocks: [
|
{
|
||||||
{
|
id: firstPost.id,
|
||||||
type: 'section',
|
postId: ts,
|
||||||
text: {
|
releaseURL: permalink || '',
|
||||||
type: 'mrkdwn',
|
status: 'posted',
|
||||||
text: post.message,
|
},
|
||||||
},
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
async comment(
|
||||||
|
id: string,
|
||||||
|
postId: string,
|
||||||
|
lastCommentId: string | undefined,
|
||||||
|
accessToken: string,
|
||||||
|
postDetails: PostDetails[],
|
||||||
|
integration: Integration
|
||||||
|
): Promise<PostResponse[]> {
|
||||||
|
const [commentPost] = postDetails;
|
||||||
|
const channel = commentPost.settings.channel;
|
||||||
|
const threadTs = lastCommentId || postId;
|
||||||
|
|
||||||
|
// Post the threaded reply
|
||||||
|
const { ts, channel: responseChannel } = await (
|
||||||
|
await fetch(`https://slack.com/api/chat.postMessage`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
channel,
|
||||||
|
username: integration.name,
|
||||||
|
icon_url: integration.picture,
|
||||||
|
thread_ts: threadTs,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: commentPost.message,
|
||||||
},
|
},
|
||||||
...(post.media?.length
|
},
|
||||||
? post.media.map((m) => ({
|
...(commentPost.media?.length
|
||||||
type: 'image',
|
? commentPost.media.map((m) => ({
|
||||||
image_url: m.path,
|
type: 'image',
|
||||||
alt_text: '',
|
image_url: m.path,
|
||||||
}))
|
alt_text: '',
|
||||||
: []),
|
}))
|
||||||
],
|
: []),
|
||||||
}),
|
],
|
||||||
})
|
}),
|
||||||
).json();
|
})
|
||||||
|
).json();
|
||||||
|
|
||||||
lastId = ts;
|
// Get permalink for the comment
|
||||||
}
|
const { permalink } = await (
|
||||||
|
await fetch(
|
||||||
|
`https://slack.com/api/chat.getPermalink?channel=${responseChannel}&message_ts=${ts}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).json();
|
||||||
|
|
||||||
return [];
|
return [
|
||||||
|
{
|
||||||
|
id: commentPost.id,
|
||||||
|
postId: ts,
|
||||||
|
releaseURL: permalink || '',
|
||||||
|
status: 'posted',
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeProfilePicture(id: string, accessToken: string, url: string) {
|
async changeProfilePicture(id: string, accessToken: string, url: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue