본문 바로가기

devLog/chatbot

2020.09.10

speakerdeck.com/kwanlae/slack-bot

 

slack bot

slack bot

speakerdeck.com

위 자료를 토대로 슬랙 챗봇을 만들어 보는 중

운영 자동화에 관심이 있어서 시도해보는 중

const botkit = require('botkit');
const keys = require('./keys');

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

controller.sqawn({
    token: keys.botAPIToken
}).startRTM();

아마 이 부분이 챗봇의 움직임을 담당하는 부분으로 추정되는데 실행해보면 에러가 발생

발생하는 에러는 

TypeError: botkit.slackbot is not a function

 

에러 그대로 리서칭해서 바로 상단에 나오는 stack overflow를 토대로 에러 수정 시도

stackoverflow.com/questions/56354839/how-to-resolve-the-botkit-slackbot-is-not-a-function-error-for-my-code-while-try

 

How to resolve the Botkit.slackbot is not a function error for my code while trying to build a slackbot using botkit?

I am trying to make a slackbot using botkit and I have written a code however I get the following error when I try to run it- TypeError: Botkit.slackbot is not a function at Object.<anonymo...< p=""> </anonymo...<>

stackoverflow.com

해당하는 에러는 수정이 되었다

 

이번에는 다른 에러가 발생

TypeError: controller.sqawn is not a function

에러 발생한 부분 지우고 다시 입력하니 이번에는 작동(뭐가 다른거지...?)

const botkit = require('botkit');
const keys = require('./keys');

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

controller.spawn({
    token: keys.botAPIToken
}).startRTM();

실행시켰을 때 나오는 콘솔 화면

챗봇의 상태가 온라인으로 바뀐 것을 확인할 수 있었음

 

const botkit = require('botkit');
const keys = require('./keys');

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

const botScope = [
    'direct_message',
    'direct_mention',
    'mention'
];

controller.hears('안녕', botScope, (bot, message) => {
    bot.reply(message, '안녕, 난 봇이야');
});

controller.spawn({
    token: keys.botAPIToken
}).startRTM();

bot.js에 코드 추가

챗봇이 '안녕'이라는 말을 받았을 경우 '안녕, 난 봇이야'를 출력할 수 있도록 동작 추가

 

콘솔에서 실행되던 챗봇을 중지시키고 추가한 코드를 바탕으로 재실행

성공적으로 작동되는 모습을 확인(좀 감이 오기 시작)

하지만 콘솔에서 slack API가 찍히는 모습은 확인이 불가(왜지...? 분명 log:true 했는데..?)

일단 넘어갔다... 

 

다음으로는 api.ai를 연동시키는 작업이었다

api.ai가 뭔지 잘 몰라 리서칭해봤다

챗봇의 ai를 제공하는 api 서비스라고 이해했다. 

 

이후에 진행되는 슬라이드를 보니 api.ai로 챗봇의 동작을 설정하는 것 보다 코드로 직접 만들어보고 싶은 마음에 진행하지 않았다.