Browse Source

allow non-message to be processed by bot (for welcome bot)

push-params
Evan Feenstra 4 years ago
parent
commit
4e836f7c66
  1. 9
      api/network/intercept.ts
  2. 2
      api/network/receive.ts
  3. 2
      api/network/send.ts
  4. 9
      dist/api/network/intercept.js
  5. 2
      dist/api/network/intercept.js.map
  6. 2
      dist/api/network/receive.js
  7. 2
      dist/api/network/receive.js.map
  8. 2
      dist/api/network/send.js
  9. 2
      dist/api/network/send.js.map

9
api/network/intercept.ts

@ -37,19 +37,26 @@ export async function isBotMsg(msg:Msg, sentByMe:boolean): Promise<boolean> {
const botsInTribe = await models.ChatBot.findAll({where:{
chatId: chat.id
}})
console.log('=> botsInTribe', botsInTribe)
if(!(botsInTribe && botsInTribe.length)) return false
await asyncForEach(botsInTribe, async botInTribe=>{
if(txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
if(botInTribe.msgTypes){
console.log('=> botInTribe.msgTypes', botInTribe)
try {
const msgTypes = JSON.parse(botInTribe.msgTypes)
if(msgTypes.includes(msgType)){
const isMsgAndHasText = msgType===constants.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `)
const isNotMsg = msgType!==constants.message_types.message
if(isMsgAndHasText || isNotMsg) {
didEmit = await emitMessageToBot(msg, botInTribe.dataValues)
}
}
} catch(e){}
} else { // no message types defined, do all?
if(txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
console.log('=> botInTribe.msgTypes else', botInTribe.dataValues)
didEmit = await emitMessageToBot(msg, botInTribe.dataValues)
}
}

2
api/network/receive.ts

@ -44,7 +44,7 @@ const botMakerTypes=[
constants.message_types.bot_cmd,
]
async function onReceive(payload){
console.log('===> onReceive',JSON.stringify(payload,null,2))
// console.log('===> onReceive',JSON.stringify(payload,null,2))
if(!(payload.type||payload.type===0)) return console.log('no payload.type')
if(botTypes.includes(payload.type)) {

2
api/network/send.ts

@ -65,7 +65,7 @@ export async function sendMessage(params) {
let yes:any = true
let no:any = null
console.log('all contactIds',contactIds)
// console.log('=> all contactIds',contactIds)
await asyncForEach(contactIds, async contactId => {
if (contactId == 1) { // dont send to self
return

9
dist/api/network/intercept.js

@ -44,20 +44,27 @@ function isBotMsg(msg, sentByMe) {
const botsInTribe = yield models_1.models.ChatBot.findAll({ where: {
chatId: chat.id
} });
console.log('=> botsInTribe', botsInTribe);
if (!(botsInTribe && botsInTribe.length))
return false;
yield asyncForEach(botsInTribe, (botInTribe) => __awaiter(this, void 0, void 0, function* () {
if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
if (botInTribe.msgTypes) {
console.log('=> botInTribe.msgTypes', botInTribe);
try {
const msgTypes = JSON.parse(botInTribe.msgTypes);
if (msgTypes.includes(msgType)) {
const isMsgAndHasText = msgType === constants.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `);
const isNotMsg = msgType !== constants.message_types.message;
if (isMsgAndHasText || isNotMsg) {
didEmit = yield emitMessageToBot(msg, botInTribe.dataValues);
}
}
}
catch (e) { }
}
else { // no message types defined, do all?
if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
console.log('=> botInTribe.msgTypes else', botInTribe.dataValues);
didEmit = yield emitMessageToBot(msg, botInTribe.dataValues);
}
}

2
dist/api/network/intercept.js.map

@ -1 +1 @@
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../api/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAkC;AAClC,wCAAyC;AACzC,8CAAkE;AAClE,6BAA4B;AAC5B,wCAAuC;AAEvC,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,IAAE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAA;QAC5C,IAAG,CAAC,GAAG;YAAE,OAAO,KAAK,CAAA;QAErB,MAAM,OAA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,QAAQ,UAAU,CAAC,OAAO,EAAE;YAC1B,KAAK,SAAS,CAAC,SAAS,CAAC,OAAO;gBAC9B,wBAAc,CAAC,GAAG,CAAC,CAAA;gBACnB,OAAO,IAAI,CAAA;YACb,KAAK,SAAS,CAAC,SAAS,CAAC,KAAK;gBAC5B,MAAM,GAAG,GAAG,MAAM,eAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC;wBAC1C,IAAI,EAAE,UAAU,CAAC,OAAO;qBACzB,EAAC,CAAC,CAAA;gBACH,OAAO,sBAAe,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC9D,KAAK,SAAS,CAAC,SAAS,CAAC,MAAM;gBAC7B,OAAO,oBAAa,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;YACvC;gBACE,OAAO,KAAK,CAAA;SACf;IACH,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"}

2
dist/api/network/receive.js

@ -53,7 +53,7 @@ const botMakerTypes = [
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('===> onReceive', JSON.stringify(payload, null, 2));
// console.log('===> onReceive',JSON.stringify(payload,null,2))
if (!(payload.type || payload.type === 0))
return console.log('no payload.type');
if (botTypes.includes(payload.type)) {

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

2
dist/api/network/send.js

@ -70,7 +70,7 @@ function sendMessage(params) {
}
let yes = true;
let no = null;
console.log('all contactIds', contactIds);
// console.log('=> all contactIds',contactIds)
yield asyncForEach(contactIds, (contactId) => __awaiter(this, void 0, void 0, function* () {
if (contactId == 1) { // dont send to self
return;

2
dist/api/network/send.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save