webfast 0.1.43 → 0.1.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,26 @@
1
- module.exports = async function(req,res,body,params,command,middleValue) {
1
+ module.exports = async function(req,res,body,params,command,middleValue,received,program) {
2
2
  console.log(`Start Telegram Function`);
3
3
  // We have the start function
4
4
 
5
- return {
6
- response : {
7
- message : `Thank you : ${command}`
5
+ // Do the script thing
6
+ if (middleValue.text.startsWith(`/`)) {
7
+ middleValue.text = `start`;
8
+ const scripting = await program.modules.telegram.script.function.check(program,command,middleValue.chat.id,middleValue,received);
9
+ console.log(`Scripting`);
10
+
11
+ if (scripting == true) {
12
+ return {
13
+ response : true
14
+ };
15
+ } else {
16
+ return {
17
+ response : {
18
+ message : `Thank you : ${command}`
19
+ }
20
+ }
8
21
  }
22
+ } else {
23
+ return true;
9
24
  }
25
+
10
26
  }
@@ -67,9 +67,15 @@ module.exports = {
67
67
  // Check typeof
68
68
  if (typeof qMatch.anwser == `object`) {
69
69
  // Match in index
70
- const matchedIndex = qMatch.anwser.indexOf(middleValue.text);
71
- if (matchedIndex != -1) {
72
- matched = qMatch;
70
+ try {
71
+ const matchedIndex = qMatch.anwser.indexOf(middleValue.text);
72
+ if (matchedIndex != -1) {
73
+ matched = qMatch;
74
+ }
75
+ } catch (err){
76
+ if (middleValue.text == `stop` || middleValue.text == `reset`) {
77
+ delete program.modules.telegram.functions.que.line[chatID];
78
+ }
73
79
  }
74
80
  } else if (qMatch.anwser == middleValue.text) {
75
81
  matched = qMatch;
@@ -105,6 +111,8 @@ module.exports = {
105
111
  console.error(`Not matched`);
106
112
  // Send command when wrong // or buttons like reset button
107
113
  // check what to do
114
+ // check if stop
115
+
108
116
  return false;
109
117
  } else {
110
118
  console.log(`Matched`);
@@ -1,5 +1,5 @@
1
1
  {
2
- "input" : "test input",
2
+ "input" : "start",
3
3
  "start" : {
4
4
  "object" : {
5
5
  "text" : "Test First Title : {{TEST}}",
@@ -42,6 +42,9 @@ module.exports = async function(program,folder) {
42
42
  let middleValue = body[key];
43
43
  // Check for split
44
44
  // Try for message
45
+ if (middleValue.chat == undefined) {
46
+ middleValue.chat = {}
47
+ }
45
48
  middleValue.chat.ts = Date.now();
46
49
  middleValue.chat.uuid = program.uuid.v4();
47
50
  let user = await program.modules.data.findOrCreate(`eventgo`,`telegram`,{
@@ -72,6 +75,7 @@ module.exports = async function(program,folder) {
72
75
  console.log(`We have received message`,received);
73
76
 
74
77
  try {
78
+ // Or check if single word
75
79
  if (middleValue.text.startsWith('/')) {
76
80
  // If it starts with a slash, it might be a command
77
81
  const parts = middleValue.text.split(' ');
@@ -136,20 +140,25 @@ module.exports = async function(program,folder) {
136
140
  // So run the function
137
141
  try {
138
142
  // Run dynamic the type of middleware
139
- const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue,received);
143
+
144
+ const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue,received,program);
140
145
  const respFunc = runFunc.response;
141
146
  // PRocess response for object
142
147
  const action = Object.keys(respFunc)[0];
143
148
 
144
149
  // switch action
145
- switch (action) {
146
- case `message`:
147
- console.log(`We have response, check for response message`);
148
- const message = respFunc[action];
149
- await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
150
- break;
151
- default:
152
- console.error(`Missing Response Action Telegram: ${action}`);
150
+ if (respFunc == true) {
151
+ // you can do something here
152
+ } else {
153
+ switch (action) {
154
+ case `message`:
155
+ console.log(`We have response, check for response message`);
156
+ const message = respFunc[action];
157
+ await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
158
+ break;
159
+ default:
160
+ console.error(`Missing Response Action Telegram: ${action}`);
161
+ }
153
162
  }
154
163
  } catch (err) {
155
164
  //console.error(err);
@@ -170,7 +179,7 @@ module.exports = async function(program,folder) {
170
179
  const command = message;
171
180
  try {
172
181
  // Run dynamic the type of middleware
173
- const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue);
182
+ const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue,program);
174
183
  const respFunc = runFunc.response;
175
184
  // PRocess response for object
176
185
  const action = Object.keys(respFunc)[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.43",
3
+ "version": "0.1.47",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps for makign it easy and fast to build ini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {