File size: 1,293 Bytes
e192d16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
"use_strict";
const { generateOfflineThreadingID } = require('../utils');
function isCallable(func) {
try {
Reflect.apply(func, null, []);
return true;
} catch (error) {
return false;
}
}
module.exports = function (defaultFuncs, api, ctx) {
return function editMessage(text, messageID, callback) {
if (!ctx.mqttClient) {
throw new Error('Not connected to MQTT');
}
ctx.wsReqNumber += 1;
ctx.wsTaskNumber += 1;
const taskPayload = {
message_id: messageID,
text: text,
};
const task = {
failure_count: null,
label: '742',
payload: JSON.stringify(taskPayload),
queue_name: 'edit_message',
task_id: ctx.wsTaskNumber,
};
const content = {
app_id: '2220391788200892',
payload: {
data_trace_id: null,
epoch_id: parseInt(generateOfflineThreadingID()),
tasks: [],
version_id: '6903494529735864',
},
request_id: ctx.wsReqNumber,
type: 3,
};
content.payload.tasks.push(task);
content.payload = JSON.stringify(content.payload);
if (isCallable(callback)) {
ctx.reqCallbacks[ctx.wsReqNumber] = callback;
}
ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
};
} |