1

slackを匿名化するbotを作成したく下記のサイトを参考に、node.jsでコードを作成しました。

Slackで匿名で投稿できるチャンネルを作った - Qiita

当たり前ですがこちらのcodeはpcの電源を切ると停止してしまいます。
この処理を常時実行させpcの電源を切ってもSlackを匿名化させたいと考えています。

現在GCP、Glitch、Herokuなどが使えそうだというのはわかりましたが、上記の処理がこれらのサービスで常時実行できるか疑問です。

非常に稚拙な質問で恐れ入りますが、上記の処理を常時行うためにはどうしたらいいかご教授ください。

var Botkit = require("./lib/Botkit.js"); //パス注意
var os = require("os");

var controller = Botkit.slackbot({ debug: true, });

var bot = controller.spawn({ token: "先ほど取得したAPI_TOKEN" }).startRTM();

controller.on("direct_message", (bot, message) => { var now = new Date(); //時刻の取得 var user_name = "名無しさん: "+ now.getFullYear()+"/"+(now.getMonth()+1)+"/"+now.getDate()+"/ "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds();

bot.reply(message, "匿名で投稿しました.");

bot.startConversation({  channel : "先ほど取得したチャンネルID" }, (err, convo) => {
    var send_message = {
      type: "message",
      channel: "先ほど取得したチャンネルID",
      text: message.text,
      username: user_name,
      thread_ts: null,
      reply_broadcast: null,
      parse: null,
      link_names: null,
      attachments: null,
      unfurl_links: null,
      unfurl_media: null,
      icon_url: null,
      icon_emoji: ":robot_face:",
      as_user: true
    }
    convo.say(send_message);
});

});

cubick
  • 20,987
  • 5
  • 25
  • 64
ortho_ryu
  • 11
  • 1

0 Answers0