!7 !include #1022367 // car bot functions !include #1022384 // Slack // no cmodule because of doPost / loadPage module oibot > DynPrintLogWithEnabled { transient new ThreadLocal msgJSON; transient RTMClient rtm; bool debug; start { if (!enabled) ret; dm_registerAs('slackModule); loadSlackToken(); if (nempty(slackToken)) ret with startSlack(); inputText("Please enter Slack bot token", voidfunc(S s) { saveTextFile(slackTokenFile(), s); startSlack(); }); } void startSlack enter { ownResource(rtm = initSlackBot(this)); } // API for evals S userID() { ret getString(msgJSON!, "user"); } S respondingToUserID() { ret userID(); } Set inputExamplesFromRules() { ret gazelle_inputExamplesFromRules(contextMaker := contextCache); } void sendTyping() { if (rtm == null) ret with print("No RTM module"); if (msgJSON! == null) ret with print("No msg"); S channel = cast msgJSON->get("channel"); print("Sending typing event in " + channel); rtm.sendMessage(jsonEncode(litmap( id := 1, type := "typing", +channel ))); } // untested void editMessage(S context, S channel, S text) ctex { ChatUpdateRequest request = ChatUpdateRequest.builder() .token(slackToken) .text(text) .ts(assertNempty(dropPrefix("slack ", context))) .channel(channel) .build(); ChatUpdateResponse response = slack.methods().chatUpdate(request); print(response); } // API for other modules void storeLineInCRUD(Map msgJSON) { main.storeLineInCRUD(msgJSON); } }