private async constructSlackBody()

in controlplane/src/core/webhooks/OrganizationWebhookService.ts [192:351]


  private async constructSlackBody(eventData: OrganizationEventData): Promise<{ blocks: any[]; attachments: any[] }> {
    switch (eventData.eventName) {
      case OrganizationEventName.FEDERATED_GRAPH_SCHEMA_UPDATED:
      case OrganizationEventName.MONOGRAPH_SCHEMA_UPDATED: {
        let graph: {
          id: string;
          name: string;
          namespace: string;
        };

        switch (eventData.eventName) {
          case OrganizationEventName.FEDERATED_GRAPH_SCHEMA_UPDATED: {
            graph = eventData.payload.federated_graph;
            break;
          }
          case OrganizationEventName.MONOGRAPH_SCHEMA_UPDATED: {
            graph = eventData.payload.monograph;
            break;
          }
        }

        const fedRepo = new FederatedGraphRepository(this.logger, this.db, eventData.payload.organization.id);
        const latestChangelogs = await fedRepo.fetchLatestFederatedGraphChangelog(graph.id);

        let linkToChangelog = `${process.env.WEB_BASE_URL}/${eventData.payload.organization.slug}/${graph.namespace}/graph/${graph.name}`;
        if (latestChangelogs) {
          linkToChangelog += `/changelog/${latestChangelogs?.schemaVersionId}`;
        }

        const tempData: { blocks: any[]; attachments: any[] } = {
          blocks: [
            {
              type: 'section',
              text: {
                type: 'mrkdwn',
                text: `🚀 Schema of the federated graph *<${process.env.WEB_BASE_URL}/${eventData.payload.organization.slug}/${graph.namespace}/graph/${graph.name} | ${graph.name}>* has been updated 🎉`,
              },
            },
          ],
          attachments: [
            {
              color: '#fafafa',
              blocks: [
                {
                  type: 'section',
                  text: {
                    type: 'mrkdwn',
                    text: `Click <${linkToChangelog}| here> for more details.`,
                  },
                },
              ],
            },
          ],
        };
        if (latestChangelogs) {
          const addedChanges = latestChangelogs.changelogs.filter((c) => c.changeType.includes('ADDED'));
          const removedChanges = latestChangelogs.changelogs.filter((c) => c.changeType.includes('REMOVED'));
          const changedChanges = latestChangelogs.changelogs.filter((c) => c.changeType.includes('CHANGED'));

          if (removedChanges.length + addedChanges.length + changedChanges.length > 20) {
            tempData.attachments.unshift({
              color: '#e11d48',
              blocks: [
                {
                  type: 'section',
                  text: {
                    type: 'mrkdwn',
                    text: `Too many changes to display. There were ${removedChanges.length + changedChanges.length} deletions and ${addedChanges.length + changedChanges.length} additions.`,
                  },
                },
              ],
            });
            return tempData;
          }

          if (changedChanges.length > 0) {
            tempData.attachments.unshift({
              color: '#8D879D',
              blocks: [
                {
                  type: 'rich_text',
                  elements: [
                    {
                      type: 'rich_text_list',
                      style: 'bullet',
                      elements: changedChanges.map((r) => ({
                        type: 'rich_text_section',
                        elements: [
                          {
                            type: 'text',
                            text: r.changeMessage,
                          },
                        ],
                      })),
                    },
                  ],
                },
              ],
            });
          }

          if (removedChanges.length > 0) {
            tempData.attachments.unshift({
              color: '#e11d48',
              blocks: [
                {
                  type: 'rich_text',
                  elements: [
                    {
                      type: 'rich_text_list',
                      style: 'bullet',
                      elements: removedChanges.map((r) => ({
                        type: 'rich_text_section',
                        elements: [
                          {
                            type: 'text',
                            text: r.changeMessage,
                          },
                        ],
                      })),
                    },
                  ],
                },
              ],
            });
          }

          if (addedChanges.length > 0) {
            tempData.attachments.unshift({
              color: '#22c55e',
              blocks: [
                {
                  type: 'rich_text',
                  elements: [
                    {
                      type: 'rich_text_list',
                      style: 'bullet',
                      elements: addedChanges.map((r) => ({
                        type: 'rich_text_section',
                        elements: [
                          {
                            type: 'text',
                            text: r.changeMessage,
                          },
                        ],
                      })),
                    },
                  ],
                },
              ],
            });
          }
        }
        return tempData;
      }
      default: {
        return { blocks: [], attachments: [] };
      }
    }
  }