How to use the @slack/client.WebClient function in @slack/client

To help you get started, we’ve selected a few @slack/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openmobilityfoundation / mds-core / packages / mds-logger / index.ts View on Github external
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function makeCensoredLogMsg(...msgs: any[]): any[] {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return makeCensoredLogMsgRecurse(msgs).map((item: any) =>
    // never print out '[object Object]'
    String(item) === '[object Object]' ? JSON.stringify(item) : item
  )
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let slackClient: any = null
if (env.SLACK_TOKEN) {
  // An access token (from your Slack app or custom integration - xoxa, xoxp, or xoxb)
  slackClient = new SlackClient(env.SLACK_TOKEN)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function sendSlack(msg: any, channelParam?: string) {
  if (!slackClient) {
    return
  }

  // See: https://api.slack.com/methods/chat.postMessage
  const channel = channelParam || env.SLACK_CHANNEL || '#sandbox'
  console.log('INFO sendSlack', channel, msg)
  try {
    const res = await slackClient.chat.postMessage({
      // This argument can be a channel ID, a DM ID, a MPDM ID, or a group ID
      token: env.SLACK_TOKEN,
      channel,
github denouche / virtual-assistant / src / interface / slack-service.js View on Github external
constructor(options) {
        super();
        
        this.slackToken = options.token;
        this.administrators = options.administrators || [];

        this.slack = null; // RtmClient
        this.slackWebClient = new WebClient(this.slackToken);
        this.authenticatedUserId = null; // Current bot id

        this.init();
        this.slack.start();
    }
github slackapi / node-slack-interactive-messages / examples / express-all-interactions / server.js View on Github external
const { WebClient } = require('@slack/client');
const { users, neighborhoods } = require('./models');
const axios = require('axios');

// Read the verification token from the environment variables
const slackVerificationToken = process.env.SLACK_VERIFICATION_TOKEN;
const slackAccessToken = process.env.SLACK_ACCESS_TOKEN;
if (!slackVerificationToken || !slackAccessToken) {
  throw new Error('Slack verification token and access token are required to run this app.');
}

// Create the adapter using the app's verification token
const slackInteractions = createMessageAdapter(process.env.SLACK_VERIFICATION_TOKEN);

// Create a Slack Web API client
const web = new WebClient(slackAccessToken);

// Initialize an Express application
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));

// Attach the adapter to the Express application as a middleware
app.use('/slack/actions', slackInteractions.expressMiddleware());

// Attach the slash command handler
app.post('/slack/commands', slackSlashCommand);

// Start the express application server
const port = process.env.PORT || 0;
http.createServer(app).listen(port, () => {
  console.log(`server listening on port ${port}`);
});
github looker / actions / src / actions / slack / oauth / slack_oauth.ts View on Github external
private slackClient(token?: string) {
    return new WebClient(token)
  }
}
github welovekpop / munar / packages / munar-adapter-slack / src / index.js View on Github external
dataStore: this.store,
        autoReconnect: true,
        autoMark: true
      })
      this.client.on(EVENTS.RTM.RTM_CONNECTION_OPENED, (self) => {
        const team = this.store.getTeamById(this.client.activeTeamId)
        const user = this.store.getUserById(this.client.activeUserId)
        debug('connected', team.name, user.name)
        this.self = new User(this, user)

        resolve()
      })
      this.client.on('message', this.onMessage)
      this.client.on('error', reject)

      this.webClient = new WebClient(this.options.token)

      this.client.login()
    })
  }
github looker / actions / src / actions / slack / legacy_slack / slack.ts View on Github external
private slackClientFromRequest(request: Hub.ActionRequest) {
    return new WebClient(request.params.slack_api_token!)
  }
github coursera / buggy / commands / me.js View on Github external
var me = new Command('me', (slack, jira, config, command) => {
  var web = new WebClient(config.slack.apiToken);

  web.users.info(slack.user_id, (slack_error, slack_results) => {
    if (slack_error) {
      var errMessage = ('i\'m sorry but i\'m having trouble looking you up in slack!');
      command.reply(slack.response_url, errMessage);
    } else {
      jira.search.search({'jql':`assignee = "${slack_results.user.profile.email}" AND resolution = Unresolved order by updated DESC`}, (jira_error, jira_results) => {
        if (jira_error) {
          var errMessage = ('i\'m sorry but i having trouble looking up your bugs in jira');
          command.reply(slack.response_url, errMessage);
        } else {
          var message = new Message(config.slack);

          if (jira_results.total > 0) {
            message.setText(slack.command + ' ' + slack.text + `\n_you are assigned to ${jira_results.total} unresolved issues_\n`);
            for (var i = 0; i < Math.min(jira_results.total, 10); i++) {
github coursera / buggy / slack / message.js View on Github external
Message.prototype.post = function() {
  var message = this;
  var web = new WebClient(message.config.apiToken);

  return new Promise((resolve, reject) => { 
    web.chat.postMessage(message.channel, message.text, message.options, (error, res) => {
      if (error) {
        reject(error);
      } else {
        resolve(res);
      }
    });
  });
}
github lmarkus / ReviewBot / lib / SlackUtils.js View on Github external
static announceAssignees(assignees, pr, slackConfig) {
        let web = new WebClient(slackConfig.token);
        assignees = assignees.map(a => `<@${a.name}>`).join(', ');
        web.chat.postMessage(slackConfig.notifyChannel, `${assignees} : You've been assigned to ${pr}`, {as_user: true}, function (err, res) {
            if (err) {
                debuglog('Error:', err);
            } else {
                debuglog('Message sent: ', res);
            }
        });
    }
};