webfast 0.1.18 → 0.1.20

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.
@@ -7,14 +7,13 @@ module.exports = {
7
7
  this.line[id] = data;
8
8
  return this.line[id];
9
9
  },
10
- get : function(id) {
10
+ get : function(id,program) {
11
11
  console.log(`Que Get Telegram`);
12
12
  // Check if in que line
13
- let indexPart = Object.keys(this.line).indexOf(id);
14
- if (indexPart == -1) {
13
+ if (program.modules.telegram.functions.que.line[id] == undefined) {
15
14
  return false;
16
15
  } else {
17
- let lineData = this.line[indexPart];
16
+ let lineData = program.modules.telegram.functions.que.line[id];
18
17
  return lineData;
19
18
  }
20
19
  },
@@ -31,22 +30,87 @@ module.exports = {
31
30
 
32
31
  let scriptStart = `start`;
33
32
  // It's new
34
- if (program.modules.telegram.script.int[command] == undefined) {
33
+ if (program.modules.telegram.script.int[command] == undefined && program.modules.telegram.functions.que.line[chatID] == undefined) {
35
34
  // Send message we don't know
36
35
 
37
36
  return false;
38
37
  }
39
38
 
40
39
  // Create the que line command
41
- const script = program.modules.telegram.script.int[command];
40
+ let script = program.modules.telegram.script.int[command];
42
41
 
43
42
  let current;
44
43
 
44
+ let theUUID = program.uuid.v4();
45
45
  if (program.modules.telegram.functions.que.line[chatID] != undefined) {
46
46
  // It's original que
47
47
  // Process response
48
48
  console.log(`It's a process`)
49
49
  current = program.modules.telegram.functions.que.line[chatID];
50
+ theUUID = current.uuid;
51
+
52
+ // Check what to do next first of all save anwser
53
+ const question = current.script[current.process];
54
+ // Grab function to process
55
+ const anwser = middleValue;
56
+
57
+ // Check if text then we need to match if not we probably need to run only function and go to next one
58
+ let matched = false;
59
+ let anwserData;
60
+ if (middleValue.text != undefined) {
61
+ console.log(`Match Text`);
62
+ // Loop through match
63
+ anwserData = middleValue.text;
64
+ for (let q in question.match.data) {
65
+ const qMatch = question.match.data[q];
66
+
67
+ // Check typeof
68
+ if (typeof qMatch.anwser == `object`) {
69
+ // Match in index
70
+ const matchedIndex = qMatch.anwser.indexOf(middleValue.text);
71
+ if (matchedIndex != -1) {
72
+ matched = qMatch;
73
+ }
74
+ } else if (qMatch.anwser == middleValue.text) {
75
+ matched = qMatch;
76
+ }
77
+ }
78
+ } else {
79
+ console.error(`Need to set anwser data`);
80
+ }
81
+
82
+ // End of match process fo matched checking
83
+ if (matched == false && current.q == true) {
84
+ // We have different data
85
+ console.error(`Not matched`);
86
+ // Send command when wrong // or buttons like reset button
87
+ // check what to do
88
+ return false;
89
+ } else {
90
+ console.log(`Matched`);
91
+ current.anwsers[current.process] = {
92
+ anwser : anwserData,
93
+ message : anwser,
94
+ ts : Date.now()
95
+ };
96
+
97
+ // Set next steps and get next steps data
98
+ try {
99
+ const nextData = current.script[matched.next];
100
+ if (nextData == undefined) {
101
+ throw new Error(`Problems getting nextData for`,current);
102
+ }
103
+ console.log(`Next Data`);
104
+ scriptStart = matched.next;
105
+ current.process = matched.next;
106
+ script = current.script;
107
+ } catch (err) {
108
+ console.error(err);
109
+ console.error(`Error getting data for next: ${matched.next}`);
110
+ }
111
+ }
112
+
113
+ console.log(`We have question anwser`);
50
114
  } else {
51
115
  // Create que line
52
116
  let setData = {
@@ -54,7 +118,9 @@ module.exports = {
54
118
  action : command,
55
119
  process : scriptStart,
56
120
  script : script,
57
- anwsers : {}
121
+ anwsers : {},
122
+ uuid : theUUID,
123
+ q : true
58
124
  }
59
125
  program.modules.telegram.functions.que.line[chatID] = setData;
60
126
  current = setData;
@@ -69,6 +135,22 @@ module.exports = {
69
135
  "{{TEST}}" : "TEST REPLACED"
70
136
  }
71
137
 
138
+ // Check if anwsers
139
+ if (Object.keys(current.anwsers).length > 0) {
140
+ // Check the anwsers
141
+ for (let anwserTXT in current.anwsers) {
142
+ const typedOf = typeof current.anwsers[anwserTXT].anwser;
143
+
144
+ if (typedOf == `string`) {
145
+ replace[`{{${String(anwserTXT).toUpperCase()}}}`] = current.anwsers[anwserTXT].anwser;
146
+ }
147
+ }
148
+ console.log(`Check loop through anwsers`);
149
+ }
150
+
151
+ // Add items to replace
152
+ console.log(`Add Items to replace`);
153
+
72
154
  // Check if text
73
155
  let toSend = {}
74
156
  if (theScript.object.text != undefined) {
@@ -92,13 +174,29 @@ module.exports = {
92
174
  }
93
175
 
94
176
  // Check if text
95
- await program.modules.telegram.functions.send(program,toSend,middleValue.chat.id);
177
+ let buttons;
178
+ // check for buttons
179
+ if (theScript.object.buttons != undefined) {
180
+ buttons = JSON.stringify(theScript.object.buttons);
181
+ // Loop through replace
182
+ for (let repKey in replace) {
183
+ const newRegx = new RegExp(repKey, 'g');
184
+ buttons = buttons.replace(newRegx,replace[repKey]);
185
+ }
186
+ buttons = JSON.parse(buttons);
187
+ }
188
+ await program.modules.telegram.functions.send(program,toSend,middleValue.chat.id,buttons);
96
189
 
190
+ // set que uuid
97
191
  program.modules.telegram.functions.que.line[chatID] = current;
192
+
98
193
  console.log(`We have script data`);
194
+
195
+ return current;
99
196
  } catch (err) {
100
197
  console.error(err);
101
198
  console.error(`Error with que something`);
199
+ return false;
102
200
  }
103
201
 
104
202
  // Do all the things that we need to do in the run
@@ -4,8 +4,8 @@ module.exports = {
4
4
  console.log(`Check if there is script`);
5
5
  try {
6
6
  const scriptData = program.modules.telegram.script.int[command];
7
- if (scriptData.length == 0) {
8
- await program.modules.telegram.functions.send(program,`${command}`,chatID,[
7
+ if (scriptData == undefined && program.modules.telegram.functions.que.get(chatID,program) == false) {
8
+ await program.modules.telegram.functions.send(program,`Sorry we don't understand: ${command}`,chatID,[
9
9
  [
10
10
  { text: 'EventGO!', web_app : { url : 'https://cloud.eventgo.today/events/list'}},
11
11
  { text: 'Create Event', callback_data: 'create_event' },
@@ -17,8 +17,16 @@ module.exports = {
17
17
 
18
18
  // Check if queData is empty otherwise we will run the script from "start", if que data is not empty we run it further
19
19
  // unt o process script
20
-
20
+ // now it's just wait
21
21
  console.log(`Went through que get`);
22
+ // Send message
23
+ if (queData == false) {
24
+ await program.modules.telegram.functions.send(program,`Sorry we don't know what to do with: ${command}`,chatID);
25
+ } else if (queData.process != `start`) {
26
+ // Process the que event
27
+ console.log(`Process the que event`);
28
+
29
+ }
22
30
  }
23
31
  console.log(`Setted`);
24
32
 
@@ -27,5 +35,8 @@ module.exports = {
27
35
  console.error(err);
28
36
  console.error(`Error Scripting`);
29
37
  }
38
+ },
39
+ response : async function() {
40
+ console.log(`Function Response`);
30
41
  }
31
42
  }
@@ -2,36 +2,56 @@
2
2
  "input" : "test input",
3
3
  "start" : {
4
4
  "object" : {
5
- "text" : "Testing Title : {{TEST}}",
5
+ "text" : "Test First Title : {{TEST}}",
6
6
  "image" : "{{URL}}app/content/images/block.png"
7
7
  },
8
8
  "match" : {
9
9
  "data" : [{
10
- "response" : "anwser text",
11
- "function" : "program.modules.bots.scripts.function",
12
- "reply_markup" : {
13
- "inline_keyboard": [[
14
- {
15
- "text": "A",
16
- "callback_data": "A1"
17
- },
18
- {
19
- "text": "B",
20
- "callback_data": "C1"
21
- }]
22
- ]
23
- },
10
+ "anwser" : ["anwser text","anwser"],
11
+ "function" : "program.modules.bots.scripts.function.response",
24
12
  "next" : "nextFunc"
25
13
  },{
26
- "response" : "other",
27
- "function" : "program.modules.bots.scripts.function",
14
+ "anwser" : "other",
15
+ "function" : "program.modules.bots.scripts.function.response",
28
16
  "next" : "nextFunc"
17
+ },{
18
+ "anwser" : "hi",
19
+ "function" : "program.modules.bots.scripts.function.response",
20
+ "next" : "nextFunc"
21
+ }]
22
+ },
23
+ "fail" : {
24
+ "response" : "start",
25
+ "function" : "program.modules.bots.scripts.function.response",
26
+ "next" : "failResponse"
27
+ }
28
+ },
29
+ "nextFunc" : {
30
+ "object" : {
31
+ "text" : "Testing Title : {{START}}",
32
+ "buttons" : [
33
+ [
34
+ { "text": "EventGO!", "web_app" : { "url" : "{{URL}}events/list"}},
35
+ { "text": "Create Event", "callback_data": "create_event" }
36
+ ]
37
+ ]
38
+ },
39
+ "match" : {
40
+ "data" : [{
41
+ "anwser" : ["create_event"],
42
+ "function" : "program.modules.bots.scripts.function.response",
43
+ "next" : "finish"
29
44
  }]
30
45
  },
31
46
  "fail" : {
32
47
  "response" : "start",
33
- "function" : "program.modules.bots.scripts.function",
48
+ "function" : "program.modules.bots.scripts.function.response",
34
49
  "next" : "failResponse"
35
50
  }
51
+ },
52
+ "failResponse" : {
53
+ "object" : {
54
+ "text" : "Sorry Something Wnt wrong : {{START}}"
55
+ }
36
56
  }
37
57
  }
@@ -44,6 +44,8 @@ module.exports = async function(program,message,id,buttons) {
44
44
  delete body.reply_to_message_id;
45
45
  telegramURL = `${telegramURL}/sendPhoto`;
46
46
  }
47
+ } else {
48
+ telegramURL = `${telegramURL}/sendMessage`;
47
49
  }
48
50
 
49
51
  // If options is there add as
@@ -52,6 +54,13 @@ module.exports = async function(program,message,id,buttons) {
52
54
  }
53
55
 
54
56
  const madeRequest = await program.modules.request.post(program,telegramURL,body)
57
+
58
+ // Save to send so we can have the id and do things
59
+ madeRequest.result.uuid = program.uuid.v4();
60
+ let saveSend = await program.modules.data.findOrCreate(`eventgo`,`send`,{
61
+ message_id : madeRequest.result.message_id
62
+ },madeRequest.result);
63
+
55
64
  console.log(`Send Message`);
56
65
  return madeRequest;
57
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {