当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript botkit.slackbot函数代码示例

本文整理汇总了TypeScript中botkit.slackbot函数的典型用法代码示例。如果您正苦于以下问题:TypeScript slackbot函数的具体用法?TypeScript slackbot怎么用?TypeScript slackbot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了slackbot函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

    constructor() {
        var dbConfig = config.get('bot.slackToken');
        this.beans = new Subject();
        this.getBeans = new Subject();
        this.controller = Botkit.slackbot({
            debug: false
        });

        this.controller.spawn({
            token: dbConfig
        }).startRTM();

        this.handleBeans();
    }
开发者ID:criticalbh,项目名称:jmx-slackbot,代码行数:14,代码来源:SlackBot.ts

示例2: Promise

    return new Promise((resolve, reject) => {
      this.controller = Botkit.slackbot({
        debug: process.env.DEBUG || false,
      });

      this.bot = this.controller.spawn({
        token: this.token
      }).startRTM();

      this.controller.hears('.*', ['direct_message', 'direct_mention', 'mention'], (bot, message) => {
        console.log(message);
        this.listeningTo.forEach((listener:ListeningTo) => {
          if (listener.pattern.exec(message.text)) {
            listener.received(message.text, message);
          }
        })
      });

      resolve(this);
    });
开发者ID:pdelanauze,项目名称:botts,代码行数:20,代码来源:SlackBotConsumer.ts

示例3: require

const databaseUrl: string = options['database-url'];
if (!databaseUrl) {
  console.log('--database-urlが指定されていません' + parser.getUsage());
  process.exit(1);
}

// Sequelizeのトランザクションを、全てのクエリで自動的に利用する設定
// http://docs.sequelizejs.com/en/latest/docs/transactions/#automatically-pass-transactions-to-all-queries
const cls = require('continuation-local-storage');
Sequelize.cls = cls.createNamespace('hx');

const botkit = require('botkit');

const controller = botkit.slackbot({
  debug: false
});

const bot = controller.spawn({
  token,
  incoming_webhook: {
    url: 'https://hooks.slack.com/services/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'
  }
})
  .startRTM(function(err: any): void {
    if (err) {
      throw new Error(err);
    }
  });

const sequelize = new Sequelize(databaseUrl, {
开发者ID:hxjp,项目名称:simekiri-bot,代码行数:30,代码来源:bot.ts

示例4: require

declare var require: any;
declare var process: any;

var botkit = require('botkit');
var os = require('os');
import { ConversationFabric, ConversationType } from "./Conversations/ConversationFabric";


var controller = botkit.slackbot({
    debug: false,
});

var bot = controller.spawn({
    token: process.env.TOKEN || 'xoxb-49895947781-WXerjwLI6CpltOcziC7RU6ze'
}).startRTM();

function createAndStartConversation(conversationType: ConversationType, bot: any, message: any) {
    let conversation = ConversationFabric.CreateConversation(conversationType, bot, message);
    conversation.Start();
}

controller.hears(['order'], 'direct_message', function (bot: any, message: any) {
    createAndStartConversation(ConversationType.CreateOrder, bot, message);
});

controller.hears(['reply'], 'direct_message', function (bot: any, message: any) {
    createAndStartConversation(ConversationType.Reply, bot, message);
});

controller.hears(['close'], 'direct_message', function (bot: any, message: any) {
    createAndStartConversation(ConversationType.CloseOrder, bot, message);
开发者ID:David-Wobrock,项目名称:helmut-slack-bot,代码行数:31,代码来源:app.ts

示例5: require

'use strict';

//Read environment variables from .env file
require("dotenv").config();

const botkit = require("botkit");

var controller = botkit.slackbot();

controller.spawn({token:process.env.BOT_TOKEN}).startRTM();

controller.hears('ping',['direct_message','direct_mention','mention'],function(bot,message) {
    bot.reply(message,'Pong.');
});
开发者ID:softwaremill,项目名称:botarium,代码行数:14,代码来源:main.ts

示例6: Redis

import * as Promise from "bluebird";

import Redis from "./redis_storage";
import {User, Task} from "./types";
import { makeTasks, getUsersFromChannels } from "./helper";

let redisURL = url.parse(process.env.REDIS_URL);
let auth = redisURL.auth || ":";
let redisStorage = new Redis({
    host: redisURL.hostname,
    port: Number(redisURL.port),
    password: auth.split(":")[1]
});

let controller = Botkit.slackbot({
    debug: true,
    storage: redisStorage,
});

let bot = controller.spawn({
    token: process.env.token,
    retry: Infinity // https://github.com/howdyai/botkit/issues/276
}).startRTM(function (err, bot) {
    if (err) {
        throw new Error(err);
    }

    if (process.env.NODE_ENV === "development") {
        askForTasks();
    } else {
        bot.api.im.open({ user: process.env.admin }, (err, res) => {
            bot.say({
开发者ID:philschonholzer,项目名称:chefbot,代码行数:32,代码来源:bot.ts

示例7: Promise

module.exports = (playlist, credentials) => {
    let controller = botkit.slackbot();
    let bot;
    let admins = [];

    let slack = {
        init: () => {
            return new Promise((resolve) => {
                // "What is the next song?"
                controller.hears([/what.*next.*(list|song|queue)/i], ['direct_message', 'direct_mention', 'mention', 'mention', 'ambient'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    let res = `It doesn't look like there are any songs in the queue`;
                    if (playlist.queue && playlist.queue.length > 1) {
                        res = `The next song will be "${playlist.queue[1].name}"`;
                    }
                    bot.reply(message, res);
                });

                // "What songs are in the playlist?"
                controller.hears([/what.*(list|song|queue)/i], ['direct_message', 'direct_mention', 'mention', 'mention', 'ambient'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    let res = 'Playlist: ';
                    if (!playlist.queue || playlist.queue.length <= 0) {
                        res = `The playlist appears to be empty\nYou can be the first ${EmojiPicker('happy')} just send me a link`;
                    } else {
                        for (let i = 0; i < playlist.queue.length && i < 5; i++) {
                            res += `\n  #${i + 1} "${playlist.queue[i].name}"`;
                        }
                    }
                    bot.reply(message, res);
                });

                // "How much time is left on the current song?"
                controller.hears([/time.*left.*song/i], ['direct_message', 'direct_mention', 'mention', 'mention', 'ambient'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    let timeLeft = new Date(playlist.getRemainingTime());
                    let minutes = Math.round(timeLeft.getMinutes() + (timeLeft.getSeconds() / 60));
                    let res = `The current song has ${minutes} minutes left`;
                    if (playlist.queue.length === 0) {
                        res = 'It does\'t look like a song is playing right now!';
                    }
                    bot.reply(message, res);
                });

                // "@musicly https://www.youtube.com/watch?v=dQw4w9WgXcQ"
                controller.hears([/((https?):\/\/)?([a-zA-Z0-9]+\.[a-zA-Z0-9])[a-zA-Z0-9\/\\?&_\-#.=]*\w/ig], ['direct_message', 'direct_mention', 'mention', 'mention'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    playlist.interpretLink(message.match[0]).then((res) => {
                        playlist.addSong(res.link);
                        console.log('RESPONSE: ' + res.response);
                        bot.reply(message, res.response);
                    }).catch((response) => {
                        bot.reply(message, response);
                    });
                });

                // "@musicly Thank you"
                controller.hears(['thank'], ['direct_message', 'direct_mention', 'mention'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    bot.reply(message, 'You\'re welcome!');
                });

                // "@musicly set this to that"
                controller.hears([/set.*to.*/i, /turn.*(on|off)/i], ['direct_message', 'direct_mention', 'mention'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    admins.forEach((admin) => {
                        if (message.user === admin.id) {
                            console.log(message.match);
                            message.match.forEach((match) => {
                                let key = '';
                                let value = '';
                                if (match.includes('to')) {
                                    let splitMatch = match.split(' to ');
                                    key = splitMatch[0];
                                    let splitKey = key.split(' ');
                                    key = splitKey[splitKey.length - 1];
                                    value = splitMatch[1].split(' ')[0];
                                } else if (match.includes('turn')) {
                                    let splitMatch = match.split('turn ');
                                    key = splitMatch[splitMatch.length - 1];
                                    value = match.includes('on');
                                }
                                credentials.set(key, value).then(() => {
                                    bot.reply(message, `I've set ${key} to ${value}`);
                                });
                            });
                        }
                    });
                });

                // "@musicly set this to that"
                controller.hears([/skip.*song/i], ['direct_message', 'direct_mention', 'mention'], (bot, message) => {
                    console.log(JSON.stringify(message));
                    admins.forEach((admin) => {
                        if (message.user === admin.id) {
                            playlist.skipSong();
                            bot.reply(message, 'Alright, skipped!');
                        }
                    });
                });
//.........这里部分代码省略.........
开发者ID:dudeofawesome,项目名称:musicly,代码行数:101,代码来源:slack.ts

示例8: express

import * as bodyParser from 'body-parser';
import * as Botkit from 'botkit';
import * as express from 'express';
import rootController from './bot';
import routes from './routes';

const PORT = process.env.PORT || 5000;
const TOKEN = process.env.SLACK_TOKEN;
const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

const controller: Botkit.Controller = Botkit.slackbot({
    interactive_replies: true,
});
const bot = controller.spawn({ token: TOKEN }).startRTM();

rootController(controller);

app.use('/', routes(bot, controller));
app.get('*', (_, res) => res.redirect('https://www.aliem.com'));
app.listen(PORT);
开发者ID:AcademicLifeInEM,项目名称:slackbot,代码行数:23,代码来源:index.ts

示例9: start

  protected start() {

    this.controller = botkit.slackbot({
      debug: config.debugMode,
    })

    this.defaultBot = this.controller.spawn({
      retry: 10,
      token: config.slackApiKey,
    }).startRTM()

    // This is a workaround to how Botkit handles teams, but this server manages only a single team.

    this.defaultBot.api.team.info({}, (err: any, response: any) => {
      if (response != null ? response.ok : undefined) {
        this.controller.saveTeam(response.team, () => console.log("Saved the team information..."))
      } else {
        throw new Error(`Could not connect to the Slack API. Ensure your Slack API key is correct. (${err})`)
      }
    })

    this.controller.setupWebserver(process.env.PORT || 3333,
      (err: any, expressWebserver: express.Application) => {

        this.controller.createWebhookEndpoints(expressWebserver)
        super.setWebserver(expressWebserver)

        if (SlackUtils.slackButtonsEnabled) {
          const actionListener = new SlackActionListener(expressWebserver, this, Looker.all)
          actionListener.bot = this.defaultBot
          this.startListener(actionListener)
        } else {
          console.log("Slack buttons are disabled or not configured.")
        }

        const eventListener = new SlackEventListener(expressWebserver, this, Looker.all)
        this.startListener(eventListener)

    })

    // Listen to the various events

    const processCommand = (bot: any, message: SentMessage, isDM = false) => {
      const context = new ReplyContext(this.defaultBot, bot, message)
      context.isDM = isDM
      this.ensureUserAuthorized(context, () => {
        this.messageHandler(context)
      })
    }

    this.controller.on("rtm_reconnect_failed", () => {
      throw new Error("Failed to reconnect to the Slack RTM API.")
    })

    this.controller.on("slash_command", (bot: any, message: SentMessage) => {
      if (!SlackUtils.checkToken(bot, message)) { return }
      processCommand(bot, message)
    })

    this.controller.on("direct_mention", (bot: any, message: SentMessage) => {
      message.text = SlackUtils.stripMessageText(message.text)
      processCommand(bot, message)
    })

    this.controller.on("direct_message", (bot: any, message: SentMessage) => {
      if (message.text.indexOf("/") !== 0) {
        message.text = SlackUtils.stripMessageText(message.text)
        processCommand(bot, message, true)
      }
    })

    this.controller.on("ambient", (bot: any, message: SentMessage) => {

      if (!message.text || (message.subtype === "bot_message")) { return }

      if (process.env.LOOKER_SLACKBOT_EXPAND_URLS !== "true") { return }

      const context = new ReplyContext(this.defaultBot, bot, message)

      this.ensureUserAuthorized(context, () => {
        // URL Expansion
        getUrls(message.text).forEach((url: string) => {
          this.urlHandler(context, url.replace("%3E", ""))
        })
      }
      , {silent: true})
    })

  }
开发者ID:DipJar,项目名称:looker-slackbot,代码行数:89,代码来源:slack_service.ts


注:本文中的botkit.slackbot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。