webfast 0.1.58 → 0.1.63

Sign up to get free protection for your applications and to get access to all the features.
@@ -124,13 +124,45 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
124
124
  console.log('WebSocket connected');
125
125
  // Start other things (e.g., send initial data)
126
126
  web.fast.que.state = true;
127
+
128
+ //alert(web.fast.tools.isMobile);
129
+ function arraySend() {
130
+ try {
131
+ if (web.fast.user != undefined || window.Telegram.WebApp.initData == ``) {
132
+ let arraySend = [];
133
+ jQuery(`[webfast-get]`).each(async function(){
134
+ const type = jQuery(this).attr(`webfast-get`);
135
+ let id = jQuery(this).attr(`id`);
136
+ if (id == undefined) {
137
+ id = await web.fast.tools.generateRandomId(8); // Generate a random ID of length 8
138
+ }
139
+ arraySend.push({
140
+ id : id,
141
+ type : type
142
+ })
143
+ })
144
+ console.log(`Send Array`,arraySend);
145
+ web.fast.tools.on.connect(arraySend);
146
+ } else {
147
+ throw new Error(`error some send`);
148
+ }
149
+ } catch (err) {
150
+ console.error(`Try again`);
151
+ setTimeout(function(){
152
+ arraySend();
153
+ },200);
154
+ }
155
+ }
156
+ // send array
157
+ arraySend();
127
158
 
128
159
  };
129
160
 
130
161
  ws.onmessage = (event) => {
131
- console.log('Received:', event.data);
162
+ //console.log('Received:', event.data);
132
163
  // Handle received data
133
164
  // Check if type user then we will walk through the data to set the data for the user
165
+ try {
134
166
  const json = JSON.parse(event.data);
135
167
  if (json.type == `user`) {
136
168
  // We have user data
@@ -177,6 +209,10 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
177
209
 
178
210
  web.fast.que.state = Date.now();
179
211
  web.fast.receive(`socket`,event.data); // Placeholder for processing response
212
+ } catch (err) {
213
+ console.error(`Error Receiving`);
214
+ console.error(event);
215
+ }
180
216
  };
181
217
 
182
218
  ws.onclose = (event) => {
@@ -51,6 +51,13 @@ module.exports = async function(program,folder) {
51
51
  id : middleValue.from.id
52
52
  },middleValue.chat);
53
53
  let typeOFF = typeof user;
54
+ if (user._id != undefined && middleValue.new_chat_member != undefined) {
55
+ if (middleValue.new_chat_member.id == user.id) {
56
+ res.send(`OK`);
57
+ return res.status(200);
58
+ }
59
+ }
60
+
54
61
  if (middleValue.chat.uuid == user.uuid || user.profileImage == undefined) {
55
62
  user.new = true;
56
63
 
@@ -73,6 +80,60 @@ module.exports = async function(program,folder) {
73
80
 
74
81
 
75
82
  console.log(`We have received message`,received);
83
+ // Check if left or not
84
+ if (received.message != undefined){
85
+ if (received.message.left_chat_member != undefined || received.message.left_chat_participant != undefined) {
86
+ console.log(`Someone left so update the databate that they left `);
87
+ const member = received.message.left_chat_participant;
88
+
89
+ // return
90
+ return true;
91
+ }
92
+
93
+ // When signup
94
+ if (received.message.new_chat_members != undefined) {
95
+ // Return because we don't need to do anything
96
+ // Loop THrough
97
+ for (let chatI in received.message.new_chat_members) {
98
+ const member = received.message.new_chat_members[chatI];
99
+ const id = member.id;
100
+ console.log(`Something with member`);
101
+
102
+ const updated =await program.modules.data.update(`eventgo`,`telegram`,{
103
+ id : id
104
+ },{
105
+ $set: {
106
+ group : Date.now()
107
+ }
108
+ });
109
+ console.log(`Updated`);
110
+
111
+ // Send notification to
112
+ if (updated.acknowledged) {
113
+ // Send Message That is subscribed to person and welcome in group
114
+ // Say hey all welcome to
115
+ if (member.first_name != undefined) {
116
+ // Send here message to group
117
+ const message = `Hey <b>${member.first_name}</b> 🎉\nWelcome to the <b>EventGO! Community</b>, here you will receive updates about new events and you are able to chat with others, enjoy and feel free to ask anything.`;
118
+ const send = await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
119
+ }
120
+
121
+ // Send here message to member that he joined and if he want to continue his
122
+ }
123
+ }
124
+
125
+ // Send message to user that they can continue with their setup
126
+ res.status(`OK`);
127
+ res.status(200);
128
+ }
129
+
130
+ // Else when group
131
+ if (received.message.chat.username == `eventgocommunity` || received.message.chat.type == `supergroup`) {
132
+ // This is when community or supergroup
133
+ console.error(`Super Group Handler Need TODO`);
134
+ return true;
135
+ }
136
+ }
76
137
 
77
138
  try {
78
139
  // Or check if single word
@@ -0,0 +1,48 @@
1
+ const { MongoClient } = require('mongodb');
2
+
3
+ module.exports = async function(db, collection, filter, update, options = {}) {
4
+ // Ensure the MongoDB connection string is provided
5
+ if (!process.env.mongo) {
6
+ console.error('MongoDB connection string not provided. Set process.env.mongo.');
7
+ process.exit(1);
8
+ }
9
+
10
+ // Define the MongoDB URI
11
+ const uri = process.env.mongo;
12
+
13
+ // Define the database and collection name
14
+ const dbName = db;
15
+ const collectionName = collection;
16
+
17
+ async function main() {
18
+ // Create a new MongoClient
19
+ const client = new MongoClient(uri);
20
+
21
+ try {
22
+ // Connect to the MongoDB server
23
+ await client.connect();
24
+ console.log('Connected to the MongoDB server');
25
+
26
+ // Select the database
27
+ const database = client.db(dbName);
28
+
29
+ // Select the collection
30
+ const collection = database.collection(collectionName);
31
+
32
+ // Perform the update operation
33
+ const result = await collection.updateOne(filter, update, options);
34
+
35
+ // Process the result
36
+ console.log('Update result:', result);
37
+
38
+ return result;
39
+ } finally {
40
+ // Close the MongoClient
41
+ await client.close();
42
+ console.log('Connection closed.');
43
+ }
44
+ }
45
+
46
+ // Execute the main function
47
+ return main().catch(console.error);
48
+ };
@@ -377,7 +377,7 @@ module.exports = async function (program) {
377
377
 
378
378
  // WebSocket on message event
379
379
  ws.on('message', async (message) => {
380
- console.log(`Received message from ${clientId}: ${message}`);
380
+ //console.log(`Received message from ${clientId}: ${message}`);
381
381
 
382
382
  try {
383
383
  // Check for function
@@ -389,7 +389,7 @@ module.exports = async function (program) {
389
389
  // Check if function is running in program modules that you can add in the init scirpt when using remote
390
390
  if (program.express.process != undefined) {
391
391
  try {
392
- let resp = await program.express.process[split[0]][split[1]][split[2]](program,ws,json,data,path);
392
+ let resp = await program.express.process[split[0]][split[1]][split[2]](program,ws,json,data,path,clientId);
393
393
  if (resp != false) {
394
394
  ws.send(JSON.stringify(resp));
395
395
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.58",
3
+ "version": "0.1.63",
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": {