• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript botkit.slackbot函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bottleneck.schedule函数代码示例发布时间:2022-05-25
下一篇:
TypeScript botframework.IBotReply类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap