diff --git a/api/bots/index.ts b/api/bots/index.ts index d117d7f..700acea 100644 --- a/api/bots/index.ts +++ b/api/bots/index.ts @@ -23,7 +23,7 @@ async function init(){ }) } -function builtinBotEmit(msg:Msg){ +function buildBotPayload(msg:Msg): SphinxBot.Message { const m = { channel:{ id: msg.chat.uuid, @@ -44,7 +44,11 @@ function builtinBotEmit(msg:Msg){ name:'Admin' }] } - SphinxBot._emit('message', m) + return m +} + +function builtinBotEmit(msg:Msg){ + SphinxBot._emit('message', buildBotPayload(msg)) } -export {init,builtinBotEmit} +export {init,builtinBotEmit,buildBotPayload} diff --git a/api/network/intercept.ts b/api/network/intercept.ts index a437083..3dde8af 100644 --- a/api/network/intercept.ts +++ b/api/network/intercept.ts @@ -1,6 +1,6 @@ import {Msg} from './interfaces' import { models } from '../models' -import {builtinBotEmit} from '../bots' +import {builtinBotEmit,buildBotPayload} from '../bots' import * as path from 'path' import fetch from 'node-fetch' @@ -79,7 +79,9 @@ async function postToBotServer(msg, botInTribe): Promise { console.log("THE BOT",bot.dataValues) const r = await fetch(bot.webhook, { method:'POST', - body:JSON.stringify(msg), + body:JSON.stringify( + buildBotPayload(msg) + ), headers:{ 'x-secret': bot.secret } diff --git a/dist/api/bots/index.js b/dist/api/bots/index.js index d8ce0d3..7bd8209 100644 --- a/dist/api/bots/index.js +++ b/dist/api/bots/index.js @@ -34,7 +34,7 @@ function init() { }); } exports.init = init; -function builtinBotEmit(msg) { +function buildBotPayload(msg) { const m = { channel: { id: msg.chat.uuid, @@ -56,7 +56,11 @@ function builtinBotEmit(msg) { name: 'Admin' }]; } - SphinxBot._emit('message', m); + return m; +} +exports.buildBotPayload = buildBotPayload; +function builtinBotEmit(msg) { + SphinxBot._emit('message', buildBotPayload(msg)); } exports.builtinBotEmit = builtinBotEmit; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/api/bots/index.js.map b/dist/api/bots/index.js.map index 35bac58..1a0a30e 100644 --- a/dist/api/bots/index.js.map +++ b/dist/api/bots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AI;AA5BZ,SAAS,eAAe,CAAC,GAAO;IAC5B,MAAM,CAAC,GAAsB;QACzB,OAAO,EAAC;YACJ,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI;YACjB,IAAI,EAAC,cAAW,CAAC;SACpB;QACD,KAAK,EAAC,cAAW,CAAC;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO;QAC5B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM;QAC1B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE;YACJ,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO;YACtB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK;YAC1B,KAAK,EAAC,EAAE;SACX;KACJ,CAAA;IACD,IAAG,GAAG,CAAC,MAAM,CAAC,IAAI,KAAG,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE;QAC7C,IAAG,CAAC,CAAC,MAAM;YAAE,CAAC,CAAC,MAAM,CAAC,KAAK,GAAC,CAAC;oBACzB,IAAI,EAAC,OAAO;iBACf,CAAC,CAAA;KACL;IACD,OAAO,CAAC,CAAA;AACZ,CAAC;AAM2B,0CAAe;AAJ3C,SAAS,cAAc,CAAC,GAAO;IAC3B,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;AACpD,CAAC;AAEY,wCAAc"} \ No newline at end of file diff --git a/dist/api/network/intercept.js b/dist/api/network/intercept.js index 6b1ed60..c8902f5 100644 --- a/dist/api/network/intercept.js +++ b/dist/api/network/intercept.js @@ -88,7 +88,7 @@ function postToBotServer(msg, botInTribe) { console.log("THE BOT", bot.dataValues); const r = yield node_fetch_1.default(bot.webhook, { method: 'POST', - body: JSON.stringify(msg), + body: JSON.stringify(bots_1.buildBotPayload(msg)), headers: { 'x-secret': bot.secret } diff --git a/dist/api/network/intercept.js.map b/dist/api/network/intercept.js.map index dfb4e86..4c4ebdc 100644 --- a/dist/api/network/intercept.js.map +++ b/dist/api/network/intercept.js.map @@ -1 +1 @@ -{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../api/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAkC;AAClC,kCAAsC;AACtC,6BAA4B;AAC5B,2CAA8B;AAE9B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E;;;EAGE;AAEF,kDAAkD;AAClD,SAAsB,QAAQ,CAAC,GAAO,EAAE,QAAgB;;QACtD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAA;QAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAA;QACxB,IAAG,OAAO,KAAG,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE;YAC5C,OAAO,KAAK,CAAA,CAAC,sCAAsC;SACpD;QACD,MAAM,IAAI,GAAG,MAAM,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC;gBAC5C,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI;aACpB,EAAC,CAAC,CAAA;QACH,IAAG,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEtB,IAAI,OAAO,GAAG,KAAK,CAAA;QAEnB,IAAG,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAC1B,qBAAc,CAAC,GAAG,CAAC,CAAA;YACnB,OAAO,GAAG,IAAI,CAAA;SACf;QAED,OAAO,CAAC,GAAG,CAAC,UAAU,EAAC,OAAO,CAAC,CAAA;QAC/B,IAAG,OAAO;YAAE,OAAO,OAAO,CAAA;QAE1B,MAAM,WAAW,GAAG,MAAM,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC;gBACtD,MAAM,EAAE,IAAI,CAAC,EAAE;aAChB,EAAC,CAAC,CAAA;QAEH,IAAG,CAAC,CAAC,WA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M,CAAC,GAAG,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC;gBAC1C,IAAI,EAAE,UAAU,CAAC,OAAO;aACzB,EAAC,CAAC,CAAA;QACH,IAAG,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM;YAAE,OAAO,KAAK,CAAA;QAC5C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACrC,MAAM,CAAC,GAAG,MAAM,oBAAK,CAAC,GAAG,CAAC,OAAO,EAAE;YACjC,MAAM,EAAC,MAAM;YACb,IAAI,EAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YACxB,OAAO,EAAC;gBACN,UAAU,EAAE,GAAG,CAAC,MAAM;aACvB;SACF,CAAC,CAAA;QACF,OAAO,CAAC,CAAC,EAAE,CAAA;IACb,CAAC;CAAA;AAED,SAAe,YAAY,CAAC,KAAK,EAAE,QAAQ;;QAC1C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjD,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SAC5C;IACF,CAAC;CAAA"} \ No newline at end of file +{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../api/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAkC;AAClC,kCAAsD;AACtD,6BAA4B;AAC5B,2CAA8B;AAE9B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E;;;EAGE;AAEF,kDAAkD;AAClD,SAAsB,QAAQ,CAAC,GAAO,EAAE,QAAgB;;QACtD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAA;QAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAA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