Edits history of script submission #22514 for ' Send Message to Channel (slack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { WebClient } from "@slack/web-api"
    
    /**
     * Send Message to Channel
     * Post a message to a channel, DM or group DM by ID. Pass `thread_ts` (the parent message's `ts`) to reply in a thread, and `blocks` to send a Block Kit layout — `text` is then the notification fallback. Returns the posted message's `ts`, needed to update it or react to it. Needs chat:write; a bot token posts to public channels it is not in only with chat:write.public.
     */
    export async function main(
      text: string,
      channel: string,
      slack: RT.Slack,
      thread_ts?: string,
      reply_broadcast?: boolean,
      blocks?: { [key: string]: any }[]
    ) {
      const web = new WebClient(slack.token)
    
      return await web.chat.postMessage(
        dropEmpty({ channel, text, thread_ts, reply_broadcast, blocks }) as any
      )
    }
    
    function dropEmpty<T extends { [key: string]: any }>(params: T) {
      return Object.fromEntries(
        Object.entries(params).filter(
          ([, v]) => v !== undefined && v !== null && v !== ""
        )
      ) as T
    }
    

    Submitted by hugo989 7 days ago

  • bun
    import { WebClient } from "@slack/web-api";
    
    type Slack = {
      token: string;
    };
    export async function main(text: string, channel: string, slack: Slack) {
      const web = new WebClient(slack.token);
    
      await web.chat.postMessage({
        channel,
        text,
      });
    }
    

    Submitted by hugo989 127 days ago