podchat 12.6.3 → 12.6.4-snapshot.3

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.
package/README.md CHANGED
@@ -1,1110 +1,1110 @@
1
- ## Synopsis
2
-
3
- **Fanap's POD** Chat service
4
-
5
- # Recent Changelog
6
-
7
- All notable changes to this project will be documented here.
8
-
9
- ## [Unreleased]
10
-
11
- - Search in threads metadata
12
-
13
- ## [4.10.0] - 2019-06-24
14
-
15
- ### Added
16
-
17
- - ACL functionalities
18
- - Getting admins list, `getThreadAdmins()`
19
- - Setting / Removing new admin with roles, `setAdmin()`
20
- - `isTyping` for users, you can call `startTyping()` and `stopTyping()` to handle typing system messages
21
- - `clearHistory()` function to fully clear thread's history
22
- - `deleteMultipleMessages()` function to delete an array of message at once
23
- - `getNotSeenDuration()` function to get the not seen time duration of user being off the application in miliseconds
24
-
25
- In order to see complete list of changelog please visit [ChangeLog](https://github.com/masoudmanson/pod-chat/blob/master/changelog.md)
26
-
27
- ## Code Example
28
-
29
- Create an Javascript file e.x `index.js` and put following code there:
30
-
31
- ```javascript
32
- var Chat = require('podchat');
33
-
34
- var params = {
35
- appId: new Date().getTime(),
36
- grantDeviceIdFromSSO: false,
37
- enableCache: true, // Enable Client side caching
38
- mapApiKey: "API_KEY_OF_NESHAN_MAP", // {**REQUIRED**} API Key of Neshan Map
39
- socketAddress: "ws://172.16.106.26:8003/ws", // {**REQUIRED**} Socket Address
40
- ssoHost: "http://172.16.110.76", // {**REQUIRED**} Socket Address
41
- platformHost: "http://172.16.106.26:8080/hamsam", // {**REQUIRED**} Platform Core Address
42
- fileServer: "http://172.16.106.26:8080/hamsam", // {**REQUIRED**} File Server Address
43
- serverName: "chat-server", // {**REQUIRED**} Server to to register on
44
- token: "SSO_TOKEN", // {**REQUIRED**} SSO Token
45
- wsConnectionWaitTime: 500, // Time out to wait for socket to get ready after open
46
- connectionRetryInterval: 5000, // Time interval to retry registering device or registering server
47
- connectionCheckTimeout: 10000, // Socket connection live time on server
48
- messageTtl: 24 * 60 * 60, // Message time to live (1 day in seonds)
49
- reconnectOnClose: true, // auto connect to socket after socket close
50
- asyncLogging: {
51
- onFunction: true, // log main actions on console
52
- onMessageReceive: true, // log received messages on console
53
- onMessageSend: true, // log sent messaged on console
54
- actualTiming: true // log actual functions running time
55
- }
56
- };
57
-
58
- var chatAgent = new Chat(params);
59
- ```
60
-
61
- ## Event Listeners
62
-
63
- Listen on these events to get updated data on your client
64
-
65
- ### chatReady
66
-
67
- This is the main Event which fires when your SDK has connected to ASYNC server and gets ready to chat.
68
- **Write your code in chatReady's callback function**
69
-
70
- ```javascript
71
- chatAgent.on("chatReady", function() {
72
- /**
73
- * Your code goes here
74
- */
75
- });
76
- ```
77
-
78
- ### error
79
-
80
- You can get all the Errors here
81
-
82
- ```javascript
83
- /**
84
- * Listen to Error Messages
85
- */
86
- chatAgent.on("error", function(error) {
87
- console.log("Error: ", error.code, error.message);
88
- });
89
- ```
90
-
91
- ### messageEvents
92
-
93
- You'll get all the Message Events here
94
-
95
- ```javascript
96
- /**
97
- * Listen to Message Events Listener
98
- */
99
- chatAgent.on("messageEvents", function(event) {
100
- var type = event.type,
101
- message = event.result.message;
102
-
103
- switch (type) {
104
- case "MESSAGE_NEW":
105
- /**
106
- * Sending Message Seen to Sender after 5 secs
107
- */
108
- setTimeout(function() {
109
- chatAgent.seen({messageId: message.id, ownerId: message.ownerId});
110
- }, 5000);
111
-
112
- break;
113
-
114
- case "MESSAGE_EDIT":
115
- break;
116
-
117
- case "MESSAGE_DELIVERY":
118
- break;
119
-
120
- case "MESSAGE_SEEN":
121
- break;
122
-
123
- default:
124
- break;
125
- }
126
- });
127
- ```
128
-
129
- ### threadEvents
130
-
131
- You'll get all the Events which are related to Threads in threadEvents listener
132
-
133
- ```javascript
134
- /**
135
- * Listen to Thread Events
136
- */
137
- chatAgent.on("threadEvents", function(event) {
138
- var type = event.type;
139
-
140
- switch (type) {
141
- case "THREAD_LAST_ACTIVITY_TIME":
142
- break;
143
-
144
- case "THREAD_NEW":
145
- break;
146
-
147
- case "THREAD_ADD_PARTICIPANTS":
148
- break;
149
-
150
- case "THREAD_REMOVE_PARTICIPANTS":
151
- break;
152
-
153
- case "THREAD_LEAVE_PARTICIPANT":
154
- break;
155
-
156
- case "THREAD_RENAME":
157
- break;
158
-
159
- case "THREAD_MUTE":
160
- break;
161
-
162
- case "THREAD_UNMUTE":
163
- break;
164
-
165
- case "THREAD_INFO_UPDATED":
166
- break;
167
-
168
- case "THREAD_UNREAD_COUNT_UPDATED":
169
- break;
170
-
171
- default:
172
- break;
173
- }
174
- });
175
- ```
176
-
177
- ### fileUploadEvents
178
-
179
- You'll get all the Events which are related to File Uploads in fileUploadEvents listener
180
-
181
- ```javascript
182
- /**
183
- * Listen to File Uploads Event Listener
184
- */
185
- chatAgent.on("fileUploadEvents", function(event) {
186
- console.log(event);
187
- });
188
- ```
189
-
190
- ## User Functions
191
-
192
- ### getUserInfo
193
-
194
- Returns current user's Profile Information
195
-
196
- ```javascript
197
- chatAgent.getUserInfo(function(userInfo) {
198
- console.log(userInfo);
199
- });
200
- ```
201
-
202
- ### getNotSeenDuration
203
- Takes an Array of user Ids and Returns the time which those users were away in miliseconds
204
-
205
- ```javascript
206
- /**
207
- * Get Unseen Duration of users
208
- *
209
- * @param {list} usersIds An array of userIds
210
- */
211
- chatAgent.getNotSeenDuration({
212
- userIds: [122, 123]
213
- }, function(result) {
214
- console.log(result);
215
- });
216
- ```
217
-
218
- ## Thread Functions
219
-
220
- ### createThread
221
-
222
- ```javascript
223
- var createThreadTypes = {
224
- NORMAL: 0,
225
- OWNER_GROUP: 1,
226
- PUBLIC_GROUP: 2,
227
- CHANNEL_GROUP: 4,
228
- CHANNEL: 8
229
- }
230
-
231
- chatAgent.createThread({
232
- title: "Thread Title Sample",
233
- type: "NORMAL",
234
- invitees: [],
235
- image: "http://yoursite.com/image.jpg",
236
- description: "Thread Description",
237
- metadata: {
238
- key: value
239
- }
240
- }, function(createThreadResult) {
241
- console.log(createThreadResult);
242
- }
243
- );
244
- ```
245
-
246
- ### getThreads
247
-
248
- ```javascript
249
- chatAgent.getThreads({
250
- count: 50,
251
- offset: 0,
252
- name: "A String to search in thread titles and return result",
253
- threadIds: [] // Array of threadIds to get
254
- }, function(threadsResult) {
255
- var threads = threadsResult.result.threads;
256
- console.log(threads);
257
- }
258
- );
259
- ```
260
-
261
- ### getHistory
262
-
263
- To get messages list of a thread, you can use getHistory() function. Accepted parameters are listed below:
264
-
265
- - threadId {number} ** Id of thread to get it's history ** `required`
266
- - count {number} ** number of messages to get ** `default is 50`
267
- - offset {number} ** offset of get query ** `default is 0`
268
- - order {string} ** order of get query ** `default is DESC`
269
- - id {string} ** ID of single message to get it's content **
270
- - uniqueIds {array} ** Array of uniqueIds to get those messages from server **
271
- - query {string} ** A string to search in messages content **
272
- - metadataCriteria {json} ** A json object to use as entry for GraphQL seach on message's metaData **
273
- - fromTime {number} ** Return messages those time is bigger than this ** `13 digits (like 1547972096473)`
274
- - fromTimeNanos {number} ** Nano Second precision for fromTime ** `9 digits (like 473533000)`
275
- - fromTimeFull {number} ** Instead of fromTme and fromTimeNanos you can send fromTimeFull ** `19 digits (like 1547972096473533000)`
276
- - toTime {number} ** Return messages those time is smaller than this ** `13 digits (like 1547972096473)`
277
- - toTimeNanos {number} ** Nano Second precision for toTime ** `9 digits (like 473533000)`
278
- - toTimeFull {number} ** Instead of toTime and toTimeNanos you can send toTimeFull ** `19 digits (like 1547972096473533000)`
279
-
280
- ```javascript
281
- chatAgent.getHistory({
282
- count: 50,
283
- offset: 0,
284
- threadId: threadId
285
- }, function(historyResult) {
286
- var history = historyResult.result.history;
287
- console.log(history);
288
- }
289
- );
290
- ```
291
-
292
- ### clearHistory
293
- This functions clears history of a given thread.
294
-
295
- ```javascript
296
- /**
297
- * CLEAR THREAD HISTORY
298
- * @param threadId
299
- */
300
- chatAgent.clearHistory({
301
- threadId: 1431
302
- }, function(result) {
303
- console.log("Clear history result", result);
304
- });
305
- ```
306
-
307
- ### getThreadParticipants
308
-
309
- ```javascript
310
- chatAgent.getThreadParticipants({
311
- count: 50,
312
- offset: 0,
313
- threadId: threadId
314
- }, function(participantsResult) {
315
- var participants = participantsResult.result.participants;
316
- console.log(participants);
317
- }
318
- );
319
- ```
320
-
321
- ### getThreadAdmins
322
- Returns a list of thread admins
323
-
324
- ```javascript
325
- chatAgent.getThreadAdmins({
326
- count: 50,
327
- offset: 0,
328
- threadId: threadId
329
- }, function(adminsResult) {
330
- var admins = adminsResult.result.participants;
331
- console.log(admins);
332
- }
333
- );
334
- ```
335
-
336
- ### setAdmin
337
- You can make an user an admin for a thread who is already a participant of that thread. In order to change a participant into
338
- an admin, all you have to do is to call `setAdmin()` and set parameters as needed.
339
- One important point is that if you set `roleOperation` parameter as `add`, the user will grant the roles you gave, and if
340
- you set `roleOperation` parameter as `remove`, those roles will be ungranted.
341
-
342
- ```javascript
343
- chatAgent.setAdmin({
344
- threadId: 10349,
345
- admins: [
346
- {
347
- userId: 123,
348
- roleOperation: 'add',
349
- roles: [
350
- 'post_channel_message',
351
- 'edit_message_of_others',
352
- 'delete_message_of_others',
353
- 'add_new_user',
354
- 'remove_user',
355
- 'thread_admin',
356
- 'add_rule_to_user',
357
- 'remove_role_from_user',
358
- 'read_thread',
359
- 'edit_thread'
360
- ]
361
- }]
362
- }, function(result) {
363
- console.log(result);
364
- });
365
- ```
366
-
367
- These roles are currently available to be set or unset:
368
-
369
- - post_channel_message
370
- - edit_message_of_others
371
- - delete_message_of_others
372
- - add_new_user
373
- - remove_user
374
- - thread_admin
375
- - add_rule_to_user
376
- - remove_role_from_user
377
- - read_thread
378
- - edit_thread
379
-
380
- ### addParticipants
381
-
382
- ```javascript
383
- chatAgent.addParticipants({
384
- threadId: threadId,
385
- contacts: [contactId1, contactId2, ...]
386
- }, function(result) {
387
- console.log(result);
388
- });
389
- ```
390
-
391
- ### removeParticipants
392
-
393
- ```javascript
394
- chatAgent.removeParticipants({
395
- threadId: threadId,
396
- participants: [participantId1, participantId2, ...]
397
- }, function(result) {
398
- console.log(result);
399
- });
400
- ```
401
-
402
- ### leaveThread
403
-
404
- ```javascript
405
- chatAgent.leaveThread({
406
- threadId: threadId
407
- }, function(result) {
408
- console.log(result);
409
- });
410
- ```
411
-
412
- ### muteThread
413
-
414
- ```javascript
415
- chatAgent.muteThread({
416
- subjectId: threadId
417
- }, function(result) {
418
- console.log("Threaded has been successfully muted!");
419
- }
420
- );
421
- ```
422
-
423
- ### unMuteThread
424
-
425
- ```javascript
426
- chatAgent.unMuteThread({
427
- subjectId: threadId
428
- }, function(result) {
429
- console.log("Threaded has been successfully unMuted!");
430
- }
431
- );
432
- ```
433
-
434
- ### renameThread
435
-
436
- ```javascript
437
- chatAgent.renameThread({
438
- title: newName,
439
- threadId: threadId
440
- }, function(result) {
441
- console.log("Threaded has been successfully Renamed!");
442
- }
443
- );
444
- ```
445
-
446
- ### updateThreadInfo
447
-
448
- ```javascript
449
- chatAgent.updateThreadInfo({
450
- threadId: threadId,
451
- image: imageUrl,
452
- description: "This is a sample description for a thread",
453
- title: "New title for thread",
454
- metadata: {
455
- name: "John Doe"
456
- }
457
- }, function(result) {
458
- console.log(result);
459
- });
460
- ```
461
-
462
- ### spamPvThread
463
-
464
- If one who is not in your contacts list, creates a P2P thread including you. You can simply SPAM him/her by calling spamPvThread() and giving it the thread's ID. Notice that the thread must be a P2P thread and the thread owner should not be in your contacts list.
465
-
466
- ```javascript
467
- chatAgent.spamPvThread({
468
- threadId: P2PThreadId
469
- }, function(result) {
470
- console.log(result);
471
- });
472
- ```
473
-
474
- ## Contact Functions
475
-
476
- ### getContacts
477
-
478
- ```javascript
479
- chatAgent.getContacts({
480
- count: 50,
481
- offset: 0
482
- }, function(contactsResult) {
483
- var contacts = contactsResult.result.contacts;
484
- console.log(contacts);
485
- });
486
- ```
487
-
488
- ### getBlocked
489
-
490
- This function return a list of people who you have blocked already.
491
-
492
- ```javascript
493
- chatAgent.getBlocked({
494
- count: 50,
495
- offset: 0
496
- }, function(contactsResult) {
497
- if (!result.hasError) {
498
- console.log(result);
499
- }
500
- });
501
- ```
502
-
503
- ### block
504
-
505
- In order to block a contact of yours, you can simply call block() function and give that contact's Id as a parameter.
506
-
507
- ```javascript
508
- chatAgent.block({
509
- contactId: 2247,
510
- // threadId: 1018,
511
- // userId: 121
512
- }, function(result) {
513
- if (!result.hasError)
514
- console.log("Contact has been successfully Blocked!");
515
- });
516
- ```
517
-
518
- ### unblock
519
-
520
- To unblock an already blocked contact, call unblock() function with block Id of that blocked contact.
521
-
522
- ```javascript
523
- chatAgent.unblock({
524
- blockId: 425,
525
- // contactId: 2247,
526
- // threadId: 1018,
527
- // userId: 122
528
- }, function(result) {
529
- if (!result.hasError)
530
- console.log("Contact has been successfully unBlocked!");
531
- });
532
- ```
533
-
534
- ### addContacts
535
-
536
- ```javascript
537
- chatAgent.addContacts({
538
- firstName: "Firstname",
539
- lastName: "Lastname",
540
- cellphoneNumber: "0999999999",
541
- email: "mail@gmail.com"
542
- }, function(result) {
543
- console.log(result);
544
- });
545
- ```
546
-
547
- ### updateContacts
548
-
549
- ```javascript
550
- chatAgent.updateContacts({
551
- id: 66, //contact's id
552
- firstName: "Firstname", // new firstname
553
- lastName: "Lastname",// new lastname
554
- cellphoneNumber: "0999999999", // new cellphone number
555
- email: "mail@gmail.com" //new email
556
- }, function(result) {
557
- console.log(result);
558
- });
559
- ```
560
-
561
- ### removeContacts
562
-
563
- ```javascript
564
- chatAgent.removeContacts({
565
- id: 234 // contact's id
566
- }, function(result) {
567
- console.log(result);
568
- });
569
- ```
570
-
571
- ### searchContacts
572
-
573
- To search in contacts list, you can use searchContacts() function. Accepted parameters to search are listed below:
574
-
575
- - cellphoneNumber {string}
576
- - email {string}
577
- - firstName {string}
578
- - lastName {string}
579
- - uniqueId {string}
580
- - id {string}
581
- - typeCode {string}
582
- - q {string}
583
- - offset {number}
584
- - size {number}
585
- extra information can be found here [listContacts() Documentation](http://sandbox.pod.land:8080/apidocs/swagger-ui.html?srv=/nzh/listContacts)
586
-
587
- ```javascript
588
- chatAgent.searchContacts({
589
- id: 234 // contact's id
590
- }, function(result) {
591
- console.log(result);
592
- });
593
- ```
594
-
595
- ## Message Functions
596
-
597
- ### sendTextMessage
598
-
599
- ```javascript
600
- chatAgent.sendTextMessage({
601
- threadId: threadId,
602
- content: messageText
603
- }, {
604
- onSent: function(result) {
605
- console.log("\nYour message has been Sent!\n");
606
- console.log(result);
607
- },
608
- onDeliver: function(result) {
609
- console.log("\nYour message has been Delivered!\n");
610
- console.log(result);
611
- },
612
- onSeen: function(result) {
613
- console.log("\nYour message has been Seen!\n");
614
- console.log(result);
615
- }
616
- });
617
- ```
618
-
619
- ### resendMessage
620
-
621
- ```javascript
622
- chatAgent.resendMessage(uniqueId, {
623
- onSent: function(result) {
624
- console.log("\nYour message has been Sent!\n");
625
- console.log(result);
626
- },
627
- onDeliver: function(result) {
628
- console.log("\nYour message has been Delivered!\n");
629
- console.log(result);
630
- },
631
- onSeen: function(result) {
632
- console.log("\nYour message has been Seen!\n");
633
- console.log(result);
634
- }
635
- }); // unique id of message to be resent
636
- ```
637
-
638
- ### cancelMessage
639
-
640
- ```javascript
641
- chatAgent.cancelMessage(uniqueId); // unique id of message to be canceled
642
- ```
643
-
644
- ### getMessageDeliveredList
645
-
646
- ```javascript
647
- chatAgent.getMessageDeliveredList({
648
- messageId: 19623
649
- });
650
- ```
651
-
652
- ### getMessageSeenList
653
-
654
- ```javascript
655
- chatAgent.getMessageSeenList({
656
- messageId: 19623
657
- });
658
- ```
659
-
660
- ### editMessage
661
-
662
- ```javascript
663
- chatAgent.editMessage({
664
- messageId: messageId,
665
- content: newMessage
666
- }, {
667
- onSent: function(result) {
668
- console.log("Edited Message has been Sent!");
669
- console.log(result);
670
- },
671
- onDeliver: function(result) {
672
- console.log("Edited Message has been Delivered!");
673
- console.log(result);
674
- },
675
- onSeen: function(result) {
676
- console.log("Edited Message has been Seen!");
677
- console.log(result);
678
- }
679
- });
680
- ```
681
-
682
- ### deleteMessage
683
-
684
- In order to delete a message for all, set `deleteForAll` parameter as `TRUE`.
685
-
686
- ```javascript
687
- /**
688
- * DELETE MESSAGE IN THREAD
689
- * @param {int} messageId
690
- * @param {boolean} deleteForAll
691
- */
692
- chatAgent.deleteMessage({
693
- messageId: messageId,
694
- deleteForAll: false
695
- }, function(result) {
696
- console.log(result);
697
- });
698
- ```
699
-
700
- ### deleteMultipleMessages
701
-
702
- In order to delete an array of messages for all, set `deleteForAll` parameter as `TRUE`.
703
-
704
- ```javascript
705
- /**
706
- * DELETE MESSAGE IN THREAD
707
- *
708
- * @param {int} messageId
709
- * @param {boolean} deleteForAll
710
- */
711
- chatAgent.deleteMultipleMessages({
712
- threadId: 10298,
713
- messageIds: [47710, 47709, 47708],
714
- deleteForAll: true
715
- }, function(result) {
716
- console.log("Delete Multiple Message Result", result);
717
- });
718
- ```
719
-
720
-
721
-
722
- ### replyMessage
723
-
724
- ```javascript
725
- chatAgent.replyMessage({
726
- threadId: threadId,
727
- repliedTo: messageId,
728
- content: message
729
- }, {
730
- onSent: function(result) {
731
- console.log("Your reply message has been Sent!");
732
- console.log(result);
733
- },
734
- onDeliver: function(result) {
735
- console.log("Your reply message has been Delivered!");
736
- console.log(result);
737
- },
738
- onSeen: function(result) {
739
- console.log("Your reply message has been Seen!");
740
- console.log(result);
741
- }
742
- });
743
- ```
744
-
745
- ### replyFileMessage
746
-
747
- ```javascript
748
- chatAgent.replyFileMessage({
749
- threadId: threadId,
750
- repliedTo: messageId,
751
- file: file,
752
- content: message
753
- }, {
754
- onSent: function(result) {
755
- console.log("Your reply message has been Sent!");
756
- console.log(result);
757
- },
758
- onDeliver: function(result) {
759
- console.log("Your reply message has been Delivered!");
760
- console.log(result);
761
- },
762
- onSeen: function(result) {
763
- console.log("Your reply message has been Seen!");
764
- console.log(result);
765
- }
766
- });
767
- ```
768
-
769
- ### forwardMessage
770
-
771
- ```javascript
772
- var messagesIds = [2539, 2538, 2537];
773
-
774
- chatAgent.forwardMessage({
775
- subjectId: threadId,
776
- content: JSON.stringify(messagesIds)
777
- }, {
778
- onSent: function(result) {
779
- console.log(result.uniqueId + " \t has been Sent! (FORWARD)");
780
- },
781
- onDeliver: function(result) {
782
- console.log(result.uniqueId + " \t has been Delivered! (FORWARD)");
783
- },
784
- onSeen: function(result) {
785
- console.log(result.uniqueId + " \t has been Seen! (FORWARD)");
786
- }
787
- });
788
- ```
789
-
790
- ## File functions
791
-
792
- ### sendFileMessage
793
-
794
- ```html
795
- <form>
796
- <fieldset>
797
- <legend>Send File Message</legend>
798
- <input type="file" name="sendFileInput" id="sendFileInput">
799
- <br>
800
- <label for="sendFileDescription">Description: </label>
801
- <input type="text" name="sendFileDescription" id="sendFileDescription">
802
- <button type="button" name="button" id="sendFileMessage">Send</button>
803
- </fieldset>
804
- </form>
805
- ```
806
-
807
- ```javascript
808
- document.getElementById("sendFileMessage").addEventListener("click", function() {
809
- var fileInput = document.getElementById("sendFileInput"),
810
- image = fileInput.files[0],
811
- content = document.getElementById("sendFileDescription").value;
812
-
813
- chatAgent.sendFileMessage({
814
- threadId: 293,
815
- file: image,
816
- content: content,
817
- metaData: {custom_name: "John Doe"}
818
- }, {
819
- onSent: function(result) {
820
- console.log(result.uniqueId + " \t has been Sent!");
821
- },
822
- onDeliver: function(result) {
823
- console.log(result.uniqueId + " \t has been Delivered!");
824
- },
825
- onSeen: function(result) {
826
- console.log(result.uniqueId + " \t has been Seen!");
827
- }
828
- });
829
- });
830
- ```
831
-
832
- ### cancelFileUpload
833
-
834
- If you want to cancel sending of the message with a file upload, You can get uploading file's uniqueId
835
- immediately after calling `sendFileMessage()` and send it as a parameter to `cancelFileUpload()`
836
-
837
- ```javascript
838
- var instantResult = chatAgent.sendFileMessage({
839
- threadId: 293,
840
- file: image,
841
- content: content
842
- }, {
843
- onSent: function(result) {},
844
- onDeliver: function(result) {},
845
- onSeen: function(result) {}
846
- });
847
-
848
- chatAgent.cancelFileUpload({
849
- uniqueId: instantResult.content.file.uniqueId
850
- }, function() {
851
- console.log("File Upload has been Canceled!");
852
- });
853
- ```
854
-
855
- ### uploadFile
856
-
857
- ```html
858
- <form>
859
- <fieldset>
860
- <legend>Upload File</legend>
861
- <input type="file" name="file" id="fileInput" value="">
862
- <button type="button" name="button" id="uploadFile">Upload File</button>
863
- <br>
864
- <div id="uploadedFile"></div>
865
- </fieldset>
866
- </form>
867
- ```
868
-
869
- ```javascript
870
- document.getElementById("uploadFile").addEventListener("click", function() {
871
- var fileInput = document.getElementById("fileInput"),
872
- file = fileInput.files[0];
873
-
874
- chatAgent.uploadFile({
875
- file: file,
876
- fileName: "Test Name"
877
- }, function(result) {
878
- if (!result.hasError) {
879
- var file = result.result;
880
- document.getElementById("uploadedFile").innerHTML = "<pre><br>Uploaded File Id: " + file.id + "<br>Uploaded File Name : " + file.name + "<br>Uploaded File HashCode : " + file.hashCode + "</pre>";
881
- }
882
- });
883
- });
884
- ```
885
-
886
- ### uploadImage
887
-
888
- ```html
889
- <form>
890
- <fieldset>
891
- <legend>Upload Image</legend>
892
- <input type="file" name="image" id="imageInput" value="">
893
- <button type="button" name="button" id="uploadImage">Upload Image</button>
894
- <br>
895
- <img id="uploadedImage" />
896
- <div id="uploadedImageData"></div>
897
- </fieldset>
898
- </form>
899
- ```
900
-
901
- ```javascript
902
- document.getElementById("uploadImage").addEventListener("click", function() {
903
- var imageInput = document.getElementById("imageInput"),
904
- image = imageInput.files[0];
905
-
906
- chatAgent.uploadImage({
907
- image: image,
908
- fileName: "Test Name",
909
- xC: 0,
910
- yC: 0,
911
- hC: 800,
912
- wC: 800
913
- }, function(result) {
914
- if (!result.hasError) {
915
- var image = result.result;
916
- document.getElementById("uploadedImage").src = "http://172.16.106.26:8080/hamsam/nzh/image?imageId=" + image.id + "&hashCode=" + image.hashCode;
917
- document.getElementById("uploadedImageData").innerHTML = "<pre><br>Uploaded Image Id: " + image.id + "<br>Uploaded Image Name : " + image.name + "<br>Uploaded Image HashCode : " + image.hashCode + "</pre>";
918
- }
919
- });
920
- });
921
- ```
922
-
923
- ### getFile
924
-
925
- ```javascript
926
- chatAgent.getFile({
927
- fileId: fileId,
928
- hashCode: hashCode,
929
- downloadable: true
930
- }, function(result) {
931
- if (!result.hasError) {
932
- var file = result.result;
933
- }
934
- });
935
- ```
936
-
937
- ### getImage
938
-
939
- ```javascript
940
- chatAgent.getImage({
941
- imageId: imageId,
942
- hashCode: hashCode,
943
- downloadable: true,
944
- actual: true
945
- }, function(result) {
946
- if (!result.hasError) {
947
- var image = result.result;
948
- }
949
- });
950
- ```
951
-
952
- ## System Messages
953
-
954
- ### isTyping
955
- To indicate that some one is currently typing in some specific thread, you can use `startTyping()` and `stopTyping()`
956
-
957
- #### startTyping
958
- This function sets an interval and sends `isTyping` system message to server every 1 second
959
-
960
- ```javascript
961
- /**
962
- * Sending isTyping message to server with an interval of 1 sec
963
- *
964
- * @param {int} threadId Id of thread that user is typing in
965
- */
966
-
967
- chatAgent.startTyping({
968
- threadId: 1431
969
- });
970
- ```
971
-
972
- #### stopTyping
973
- Because user can only type in one thread at time, so there will be only one isTypingInterval available. This function
974
- clears it and stops sending the system messages.
975
-
976
- ```javascript
977
- /**
978
- * Stops Sending isTyping message to server
979
- */
980
-
981
- chatAgent.stopTyping();
982
- ```
983
-
984
-
985
- ## Embedded Map Service functions
986
-
987
- ### mapReverse
988
-
989
- This function takes a Geo Location and returns its address back
990
-
991
- ```javascript
992
- /**
993
- * Get Address of a GeoLocation point
994
- *
995
- * @param {float} lat Latitute of the Location
996
- * @param {float} lng Longtitute of the Location
997
- */
998
- chatAgent.mapReverse({
999
- lat: 35.7003508,
1000
- lng: 51.3376460
1001
- }, function(result) {
1002
- console.log(result);
1003
- });
1004
- ```
1005
-
1006
- ### mapSearch
1007
-
1008
- This function takes a Geo Location and a Search term and returns an array of Nearby places containing that search term
1009
-
1010
- ```javascript
1011
- /**
1012
- * Get nearby places names as "term" keyword
1013
- * around the given GeoLocation
1014
- *
1015
- * @param {float} lat Latitute of the Location
1016
- * @param {float} lng Longtitute of the Location
1017
- * @param {string} term Search term to be searched
1018
- */
1019
- chatAgent.mapSearch({
1020
- lat: 35.7003508,
1021
- lng: 51.3376460,
1022
- term: "فروشگاه"
1023
- }, function(result) {
1024
- console.log(result);
1025
- });
1026
- ```
1027
-
1028
- ### mapRouting
1029
-
1030
- This function takes two Geo Locations and returns the route between them
1031
-
1032
- ```javascript
1033
- /**
1034
- * Get routing between two given GeoLocations
1035
- *
1036
- * @param {object} origin Lat & Lng of Origin as a JSON
1037
- * @param {object} destination Lat & Lng of Destination as a JSON
1038
- * @param {boolean} alternative Give Alternative Routs too
1039
- */
1040
- chatAgent.mapRouting({
1041
- origin: {
1042
- lat: 35.7003508,
1043
- lng: 51.3376460
1044
- },
1045
- destination: {
1046
- lat: 35.7343510,
1047
- lng: 50.3376472
1048
- },
1049
- alternative: true
1050
- }, function(result) {
1051
- console.log(result);
1052
- });
1053
- ```
1054
-
1055
- ### mapStaticImage
1056
-
1057
- This function takes a Geo Locations and returns the link of static map image related that area
1058
-
1059
- ```javascript
1060
- /**
1061
- * Get Static Image of a GeoLocation
1062
- *
1063
- * @param {string} type Map style (default standard-night)
1064
- * @param {int} zoom Map zoom (default 15)
1065
- * @param {object} center Lat & Lng of Map center as a JSON
1066
- * @param {int} width width of image in pixels (default 800px)
1067
- * @param {int} height height of image in pixels (default 600px)
1068
- */
1069
- chatAgent.mapStaticImage({
1070
- type: "standard-night",
1071
- zoom: 15,
1072
- center: {
1073
- lat: 35.7003508,
1074
- lng: 51.3376462
1075
- },
1076
- width: 800,
1077
- height: 500
1078
- }, function(result) {
1079
- console.log(result);
1080
- });
1081
- ```
1082
-
1083
- ## Installation
1084
-
1085
- ```javascript
1086
- npm install podchat --save
1087
- ```
1088
-
1089
- ## API Reference
1090
-
1091
- [API Docs from POD](http://docs.pod.land/v1.0.0.0/Chat/javascript/783/Introduction)
1092
-
1093
- ## Tests
1094
-
1095
- ```javascript
1096
- npm test
1097
- ```
1098
-
1099
- ## Contributors
1100
-
1101
- You can send me your thoughts about making this repo great :)
1102
- [Email](masoudmanson@gmail.com)
1103
-
1104
- ## License
1105
-
1106
- Under MIT License.
1107
-
1108
- ## Acknowledgments
1109
-
1110
- A very special thanks to Ali Khanbabaei ([khanbabaeifanap](https://github.com/khanbabaeifanap)), who wrote the early version of chat service and helped me a lot with this repo.
1
+ ## Synopsis
2
+
3
+ **Fanap's POD** Chat service
4
+
5
+ # Recent Changelog
6
+
7
+ All notable changes to this project will be documented here.
8
+
9
+ ## [Unreleased]
10
+
11
+ - Search in threads metadata
12
+
13
+ ## [4.10.0] - 2019-06-24
14
+
15
+ ### Added
16
+
17
+ - ACL functionalities
18
+ - Getting admins list, `getThreadAdmins()`
19
+ - Setting / Removing new admin with roles, `setAdmin()`
20
+ - `isTyping` for users, you can call `startTyping()` and `stopTyping()` to handle typing system messages
21
+ - `clearHistory()` function to fully clear thread's history
22
+ - `deleteMultipleMessages()` function to delete an array of message at once
23
+ - `getNotSeenDuration()` function to get the not seen time duration of user being off the application in miliseconds
24
+
25
+ In order to see complete list of changelog please visit [ChangeLog](https://github.com/masoudmanson/pod-chat/blob/master/changelog.md)
26
+
27
+ ## Code Example
28
+
29
+ Create an Javascript file e.x `index.js` and put following code there:
30
+
31
+ ```javascript
32
+ var Chat = require('podchat');
33
+
34
+ var params = {
35
+ appId: new Date().getTime(),
36
+ grantDeviceIdFromSSO: false,
37
+ enableCache: true, // Enable Client side caching
38
+ mapApiKey: "API_KEY_OF_NESHAN_MAP", // {**REQUIRED**} API Key of Neshan Map
39
+ socketAddress: "ws://172.16.106.26:8003/ws", // {**REQUIRED**} Socket Address
40
+ ssoHost: "http://172.16.110.76", // {**REQUIRED**} Socket Address
41
+ platformHost: "http://172.16.106.26:8080/hamsam", // {**REQUIRED**} Platform Core Address
42
+ fileServer: "http://172.16.106.26:8080/hamsam", // {**REQUIRED**} File Server Address
43
+ serverName: "chat-server", // {**REQUIRED**} Server to to register on
44
+ token: "SSO_TOKEN", // {**REQUIRED**} SSO Token
45
+ wsConnectionWaitTime: 500, // Time out to wait for socket to get ready after open
46
+ connectionRetryInterval: 5000, // Time interval to retry registering device or registering server
47
+ connectionCheckTimeout: 10000, // Socket connection live time on server
48
+ messageTtl: 24 * 60 * 60, // Message time to live (1 day in seonds)
49
+ reconnectOnClose: true, // auto connect to socket after socket close
50
+ asyncLogging: {
51
+ onFunction: true, // log main actions on console
52
+ onMessageReceive: true, // log received messages on console
53
+ onMessageSend: true, // log sent messaged on console
54
+ actualTiming: true // log actual functions running time
55
+ }
56
+ };
57
+
58
+ var chatAgent = new Chat(params);
59
+ ```
60
+
61
+ ## Event Listeners
62
+
63
+ Listen on these events to get updated data on your client
64
+
65
+ ### chatReady
66
+
67
+ This is the main Event which fires when your SDK has connected to ASYNC server and gets ready to chat.
68
+ **Write your code in chatReady's callback function**
69
+
70
+ ```javascript
71
+ chatAgent.on("chatReady", function() {
72
+ /**
73
+ * Your code goes here
74
+ */
75
+ });
76
+ ```
77
+
78
+ ### error
79
+
80
+ You can get all the Errors here
81
+
82
+ ```javascript
83
+ /**
84
+ * Listen to Error Messages
85
+ */
86
+ chatAgent.on("error", function(error) {
87
+ console.log("Error: ", error.code, error.message);
88
+ });
89
+ ```
90
+
91
+ ### messageEvents
92
+
93
+ You'll get all the Message Events here
94
+
95
+ ```javascript
96
+ /**
97
+ * Listen to Message Events Listener
98
+ */
99
+ chatAgent.on("messageEvents", function(event) {
100
+ var type = event.type,
101
+ message = event.result.message;
102
+
103
+ switch (type) {
104
+ case "MESSAGE_NEW":
105
+ /**
106
+ * Sending Message Seen to Sender after 5 secs
107
+ */
108
+ setTimeout(function() {
109
+ chatAgent.seen({messageId: message.id, ownerId: message.ownerId});
110
+ }, 5000);
111
+
112
+ break;
113
+
114
+ case "MESSAGE_EDIT":
115
+ break;
116
+
117
+ case "MESSAGE_DELIVERY":
118
+ break;
119
+
120
+ case "MESSAGE_SEEN":
121
+ break;
122
+
123
+ default:
124
+ break;
125
+ }
126
+ });
127
+ ```
128
+
129
+ ### threadEvents
130
+
131
+ You'll get all the Events which are related to Threads in threadEvents listener
132
+
133
+ ```javascript
134
+ /**
135
+ * Listen to Thread Events
136
+ */
137
+ chatAgent.on("threadEvents", function(event) {
138
+ var type = event.type;
139
+
140
+ switch (type) {
141
+ case "THREAD_LAST_ACTIVITY_TIME":
142
+ break;
143
+
144
+ case "THREAD_NEW":
145
+ break;
146
+
147
+ case "THREAD_ADD_PARTICIPANTS":
148
+ break;
149
+
150
+ case "THREAD_REMOVE_PARTICIPANTS":
151
+ break;
152
+
153
+ case "THREAD_LEAVE_PARTICIPANT":
154
+ break;
155
+
156
+ case "THREAD_RENAME":
157
+ break;
158
+
159
+ case "THREAD_MUTE":
160
+ break;
161
+
162
+ case "THREAD_UNMUTE":
163
+ break;
164
+
165
+ case "THREAD_INFO_UPDATED":
166
+ break;
167
+
168
+ case "THREAD_UNREAD_COUNT_UPDATED":
169
+ break;
170
+
171
+ default:
172
+ break;
173
+ }
174
+ });
175
+ ```
176
+
177
+ ### fileUploadEvents
178
+
179
+ You'll get all the Events which are related to File Uploads in fileUploadEvents listener
180
+
181
+ ```javascript
182
+ /**
183
+ * Listen to File Uploads Event Listener
184
+ */
185
+ chatAgent.on("fileUploadEvents", function(event) {
186
+ console.log(event);
187
+ });
188
+ ```
189
+
190
+ ## User Functions
191
+
192
+ ### getUserInfo
193
+
194
+ Returns current user's Profile Information
195
+
196
+ ```javascript
197
+ chatAgent.getUserInfo(function(userInfo) {
198
+ console.log(userInfo);
199
+ });
200
+ ```
201
+
202
+ ### getNotSeenDuration
203
+ Takes an Array of user Ids and Returns the time which those users were away in miliseconds
204
+
205
+ ```javascript
206
+ /**
207
+ * Get Unseen Duration of users
208
+ *
209
+ * @param {list} usersIds An array of userIds
210
+ */
211
+ chatAgent.getNotSeenDuration({
212
+ userIds: [122, 123]
213
+ }, function(result) {
214
+ console.log(result);
215
+ });
216
+ ```
217
+
218
+ ## Thread Functions
219
+
220
+ ### createThread
221
+
222
+ ```javascript
223
+ var createThreadTypes = {
224
+ NORMAL: 0,
225
+ OWNER_GROUP: 1,
226
+ PUBLIC_GROUP: 2,
227
+ CHANNEL_GROUP: 4,
228
+ CHANNEL: 8
229
+ }
230
+
231
+ chatAgent.createThread({
232
+ title: "Thread Title Sample",
233
+ type: "NORMAL",
234
+ invitees: [],
235
+ image: "http://yoursite.com/image.jpg",
236
+ description: "Thread Description",
237
+ metadata: {
238
+ key: value
239
+ }
240
+ }, function(createThreadResult) {
241
+ console.log(createThreadResult);
242
+ }
243
+ );
244
+ ```
245
+
246
+ ### getThreads
247
+
248
+ ```javascript
249
+ chatAgent.getThreads({
250
+ count: 50,
251
+ offset: 0,
252
+ name: "A String to search in thread titles and return result",
253
+ threadIds: [] // Array of threadIds to get
254
+ }, function(threadsResult) {
255
+ var threads = threadsResult.result.threads;
256
+ console.log(threads);
257
+ }
258
+ );
259
+ ```
260
+
261
+ ### getHistory
262
+
263
+ To get messages list of a thread, you can use getHistory() function. Accepted parameters are listed below:
264
+
265
+ - threadId {number} ** Id of thread to get it's history ** `required`
266
+ - count {number} ** number of messages to get ** `default is 50`
267
+ - offset {number} ** offset of get query ** `default is 0`
268
+ - order {string} ** order of get query ** `default is DESC`
269
+ - id {string} ** ID of single message to get it's content **
270
+ - uniqueIds {array} ** Array of uniqueIds to get those messages from server **
271
+ - query {string} ** A string to search in messages content **
272
+ - metadataCriteria {json} ** A json object to use as entry for GraphQL seach on message's metaData **
273
+ - fromTime {number} ** Return messages those time is bigger than this ** `13 digits (like 1547972096473)`
274
+ - fromTimeNanos {number} ** Nano Second precision for fromTime ** `9 digits (like 473533000)`
275
+ - fromTimeFull {number} ** Instead of fromTme and fromTimeNanos you can send fromTimeFull ** `19 digits (like 1547972096473533000)`
276
+ - toTime {number} ** Return messages those time is smaller than this ** `13 digits (like 1547972096473)`
277
+ - toTimeNanos {number} ** Nano Second precision for toTime ** `9 digits (like 473533000)`
278
+ - toTimeFull {number} ** Instead of toTime and toTimeNanos you can send toTimeFull ** `19 digits (like 1547972096473533000)`
279
+
280
+ ```javascript
281
+ chatAgent.getHistory({
282
+ count: 50,
283
+ offset: 0,
284
+ threadId: threadId
285
+ }, function(historyResult) {
286
+ var history = historyResult.result.history;
287
+ console.log(history);
288
+ }
289
+ );
290
+ ```
291
+
292
+ ### clearHistory
293
+ This functions clears history of a given thread.
294
+
295
+ ```javascript
296
+ /**
297
+ * CLEAR THREAD HISTORY
298
+ * @param threadId
299
+ */
300
+ chatAgent.clearHistory({
301
+ threadId: 1431
302
+ }, function(result) {
303
+ console.log("Clear history result", result);
304
+ });
305
+ ```
306
+
307
+ ### getThreadParticipants
308
+
309
+ ```javascript
310
+ chatAgent.getThreadParticipants({
311
+ count: 50,
312
+ offset: 0,
313
+ threadId: threadId
314
+ }, function(participantsResult) {
315
+ var participants = participantsResult.result.participants;
316
+ console.log(participants);
317
+ }
318
+ );
319
+ ```
320
+
321
+ ### getThreadAdmins
322
+ Returns a list of thread admins
323
+
324
+ ```javascript
325
+ chatAgent.getThreadAdmins({
326
+ count: 50,
327
+ offset: 0,
328
+ threadId: threadId
329
+ }, function(adminsResult) {
330
+ var admins = adminsResult.result.participants;
331
+ console.log(admins);
332
+ }
333
+ );
334
+ ```
335
+
336
+ ### setAdmin
337
+ You can make an user an admin for a thread who is already a participant of that thread. In order to change a participant into
338
+ an admin, all you have to do is to call `setAdmin()` and set parameters as needed.
339
+ One important point is that if you set `roleOperation` parameter as `add`, the user will grant the roles you gave, and if
340
+ you set `roleOperation` parameter as `remove`, those roles will be ungranted.
341
+
342
+ ```javascript
343
+ chatAgent.setAdmin({
344
+ threadId: 10349,
345
+ admins: [
346
+ {
347
+ userId: 123,
348
+ roleOperation: 'add',
349
+ roles: [
350
+ 'post_channel_message',
351
+ 'edit_message_of_others',
352
+ 'delete_message_of_others',
353
+ 'add_new_user',
354
+ 'remove_user',
355
+ 'thread_admin',
356
+ 'add_rule_to_user',
357
+ 'remove_role_from_user',
358
+ 'read_thread',
359
+ 'edit_thread'
360
+ ]
361
+ }]
362
+ }, function(result) {
363
+ console.log(result);
364
+ });
365
+ ```
366
+
367
+ These roles are currently available to be set or unset:
368
+
369
+ - post_channel_message
370
+ - edit_message_of_others
371
+ - delete_message_of_others
372
+ - add_new_user
373
+ - remove_user
374
+ - thread_admin
375
+ - add_rule_to_user
376
+ - remove_role_from_user
377
+ - read_thread
378
+ - edit_thread
379
+
380
+ ### addParticipants
381
+
382
+ ```javascript
383
+ chatAgent.addParticipants({
384
+ threadId: threadId,
385
+ contacts: [contactId1, contactId2, ...]
386
+ }, function(result) {
387
+ console.log(result);
388
+ });
389
+ ```
390
+
391
+ ### removeParticipants
392
+
393
+ ```javascript
394
+ chatAgent.removeParticipants({
395
+ threadId: threadId,
396
+ participants: [participantId1, participantId2, ...]
397
+ }, function(result) {
398
+ console.log(result);
399
+ });
400
+ ```
401
+
402
+ ### leaveThread
403
+
404
+ ```javascript
405
+ chatAgent.leaveThread({
406
+ threadId: threadId
407
+ }, function(result) {
408
+ console.log(result);
409
+ });
410
+ ```
411
+
412
+ ### muteThread
413
+
414
+ ```javascript
415
+ chatAgent.muteThread({
416
+ subjectId: threadId
417
+ }, function(result) {
418
+ console.log("Threaded has been successfully muted!");
419
+ }
420
+ );
421
+ ```
422
+
423
+ ### unMuteThread
424
+
425
+ ```javascript
426
+ chatAgent.unMuteThread({
427
+ subjectId: threadId
428
+ }, function(result) {
429
+ console.log("Threaded has been successfully unMuted!");
430
+ }
431
+ );
432
+ ```
433
+
434
+ ### renameThread
435
+
436
+ ```javascript
437
+ chatAgent.renameThread({
438
+ title: newName,
439
+ threadId: threadId
440
+ }, function(result) {
441
+ console.log("Threaded has been successfully Renamed!");
442
+ }
443
+ );
444
+ ```
445
+
446
+ ### updateThreadInfo
447
+
448
+ ```javascript
449
+ chatAgent.updateThreadInfo({
450
+ threadId: threadId,
451
+ image: imageUrl,
452
+ description: "This is a sample description for a thread",
453
+ title: "New title for thread",
454
+ metadata: {
455
+ name: "John Doe"
456
+ }
457
+ }, function(result) {
458
+ console.log(result);
459
+ });
460
+ ```
461
+
462
+ ### spamPvThread
463
+
464
+ If one who is not in your contacts list, creates a P2P thread including you. You can simply SPAM him/her by calling spamPvThread() and giving it the thread's ID. Notice that the thread must be a P2P thread and the thread owner should not be in your contacts list.
465
+
466
+ ```javascript
467
+ chatAgent.spamPvThread({
468
+ threadId: P2PThreadId
469
+ }, function(result) {
470
+ console.log(result);
471
+ });
472
+ ```
473
+
474
+ ## Contact Functions
475
+
476
+ ### getContacts
477
+
478
+ ```javascript
479
+ chatAgent.getContacts({
480
+ count: 50,
481
+ offset: 0
482
+ }, function(contactsResult) {
483
+ var contacts = contactsResult.result.contacts;
484
+ console.log(contacts);
485
+ });
486
+ ```
487
+
488
+ ### getBlocked
489
+
490
+ This function return a list of people who you have blocked already.
491
+
492
+ ```javascript
493
+ chatAgent.getBlocked({
494
+ count: 50,
495
+ offset: 0
496
+ }, function(contactsResult) {
497
+ if (!result.hasError) {
498
+ console.log(result);
499
+ }
500
+ });
501
+ ```
502
+
503
+ ### block
504
+
505
+ In order to block a contact of yours, you can simply call block() function and give that contact's Id as a parameter.
506
+
507
+ ```javascript
508
+ chatAgent.block({
509
+ contactId: 2247,
510
+ // threadId: 1018,
511
+ // userId: 121
512
+ }, function(result) {
513
+ if (!result.hasError)
514
+ console.log("Contact has been successfully Blocked!");
515
+ });
516
+ ```
517
+
518
+ ### unblock
519
+
520
+ To unblock an already blocked contact, call unblock() function with block Id of that blocked contact.
521
+
522
+ ```javascript
523
+ chatAgent.unblock({
524
+ blockId: 425,
525
+ // contactId: 2247,
526
+ // threadId: 1018,
527
+ // userId: 122
528
+ }, function(result) {
529
+ if (!result.hasError)
530
+ console.log("Contact has been successfully unBlocked!");
531
+ });
532
+ ```
533
+
534
+ ### addContacts
535
+
536
+ ```javascript
537
+ chatAgent.addContacts({
538
+ firstName: "Firstname",
539
+ lastName: "Lastname",
540
+ cellphoneNumber: "0999999999",
541
+ email: "mail@gmail.com"
542
+ }, function(result) {
543
+ console.log(result);
544
+ });
545
+ ```
546
+
547
+ ### updateContacts
548
+
549
+ ```javascript
550
+ chatAgent.updateContacts({
551
+ id: 66, //contact's id
552
+ firstName: "Firstname", // new firstname
553
+ lastName: "Lastname",// new lastname
554
+ cellphoneNumber: "0999999999", // new cellphone number
555
+ email: "mail@gmail.com" //new email
556
+ }, function(result) {
557
+ console.log(result);
558
+ });
559
+ ```
560
+
561
+ ### removeContacts
562
+
563
+ ```javascript
564
+ chatAgent.removeContacts({
565
+ id: 234 // contact's id
566
+ }, function(result) {
567
+ console.log(result);
568
+ });
569
+ ```
570
+
571
+ ### searchContacts
572
+
573
+ To search in contacts list, you can use searchContacts() function. Accepted parameters to search are listed below:
574
+
575
+ - cellphoneNumber {string}
576
+ - email {string}
577
+ - firstName {string}
578
+ - lastName {string}
579
+ - uniqueId {string}
580
+ - id {string}
581
+ - typeCode {string}
582
+ - q {string}
583
+ - offset {number}
584
+ - size {number}
585
+ extra information can be found here [listContacts() Documentation](http://sandbox.pod.land:8080/apidocs/swagger-ui.html?srv=/nzh/listContacts)
586
+
587
+ ```javascript
588
+ chatAgent.searchContacts({
589
+ id: 234 // contact's id
590
+ }, function(result) {
591
+ console.log(result);
592
+ });
593
+ ```
594
+
595
+ ## Message Functions
596
+
597
+ ### sendTextMessage
598
+
599
+ ```javascript
600
+ chatAgent.sendTextMessage({
601
+ threadId: threadId,
602
+ content: messageText
603
+ }, {
604
+ onSent: function(result) {
605
+ console.log("\nYour message has been Sent!\n");
606
+ console.log(result);
607
+ },
608
+ onDeliver: function(result) {
609
+ console.log("\nYour message has been Delivered!\n");
610
+ console.log(result);
611
+ },
612
+ onSeen: function(result) {
613
+ console.log("\nYour message has been Seen!\n");
614
+ console.log(result);
615
+ }
616
+ });
617
+ ```
618
+
619
+ ### resendMessage
620
+
621
+ ```javascript
622
+ chatAgent.resendMessage(uniqueId, {
623
+ onSent: function(result) {
624
+ console.log("\nYour message has been Sent!\n");
625
+ console.log(result);
626
+ },
627
+ onDeliver: function(result) {
628
+ console.log("\nYour message has been Delivered!\n");
629
+ console.log(result);
630
+ },
631
+ onSeen: function(result) {
632
+ console.log("\nYour message has been Seen!\n");
633
+ console.log(result);
634
+ }
635
+ }); // unique id of message to be resent
636
+ ```
637
+
638
+ ### cancelMessage
639
+
640
+ ```javascript
641
+ chatAgent.cancelMessage(uniqueId); // unique id of message to be canceled
642
+ ```
643
+
644
+ ### getMessageDeliveredList
645
+
646
+ ```javascript
647
+ chatAgent.getMessageDeliveredList({
648
+ messageId: 19623
649
+ });
650
+ ```
651
+
652
+ ### getMessageSeenList
653
+
654
+ ```javascript
655
+ chatAgent.getMessageSeenList({
656
+ messageId: 19623
657
+ });
658
+ ```
659
+
660
+ ### editMessage
661
+
662
+ ```javascript
663
+ chatAgent.editMessage({
664
+ messageId: messageId,
665
+ content: newMessage
666
+ }, {
667
+ onSent: function(result) {
668
+ console.log("Edited Message has been Sent!");
669
+ console.log(result);
670
+ },
671
+ onDeliver: function(result) {
672
+ console.log("Edited Message has been Delivered!");
673
+ console.log(result);
674
+ },
675
+ onSeen: function(result) {
676
+ console.log("Edited Message has been Seen!");
677
+ console.log(result);
678
+ }
679
+ });
680
+ ```
681
+
682
+ ### deleteMessage
683
+
684
+ In order to delete a message for all, set `deleteForAll` parameter as `TRUE`.
685
+
686
+ ```javascript
687
+ /**
688
+ * DELETE MESSAGE IN THREAD
689
+ * @param {int} messageId
690
+ * @param {boolean} deleteForAll
691
+ */
692
+ chatAgent.deleteMessage({
693
+ messageId: messageId,
694
+ deleteForAll: false
695
+ }, function(result) {
696
+ console.log(result);
697
+ });
698
+ ```
699
+
700
+ ### deleteMultipleMessages
701
+
702
+ In order to delete an array of messages for all, set `deleteForAll` parameter as `TRUE`.
703
+
704
+ ```javascript
705
+ /**
706
+ * DELETE MESSAGE IN THREAD
707
+ *
708
+ * @param {int} messageId
709
+ * @param {boolean} deleteForAll
710
+ */
711
+ chatAgent.deleteMultipleMessages({
712
+ threadId: 10298,
713
+ messageIds: [47710, 47709, 47708],
714
+ deleteForAll: true
715
+ }, function(result) {
716
+ console.log("Delete Multiple Message Result", result);
717
+ });
718
+ ```
719
+
720
+
721
+
722
+ ### replyMessage
723
+
724
+ ```javascript
725
+ chatAgent.replyMessage({
726
+ threadId: threadId,
727
+ repliedTo: messageId,
728
+ content: message
729
+ }, {
730
+ onSent: function(result) {
731
+ console.log("Your reply message has been Sent!");
732
+ console.log(result);
733
+ },
734
+ onDeliver: function(result) {
735
+ console.log("Your reply message has been Delivered!");
736
+ console.log(result);
737
+ },
738
+ onSeen: function(result) {
739
+ console.log("Your reply message has been Seen!");
740
+ console.log(result);
741
+ }
742
+ });
743
+ ```
744
+
745
+ ### replyFileMessage
746
+
747
+ ```javascript
748
+ chatAgent.replyFileMessage({
749
+ threadId: threadId,
750
+ repliedTo: messageId,
751
+ file: file,
752
+ content: message
753
+ }, {
754
+ onSent: function(result) {
755
+ console.log("Your reply message has been Sent!");
756
+ console.log(result);
757
+ },
758
+ onDeliver: function(result) {
759
+ console.log("Your reply message has been Delivered!");
760
+ console.log(result);
761
+ },
762
+ onSeen: function(result) {
763
+ console.log("Your reply message has been Seen!");
764
+ console.log(result);
765
+ }
766
+ });
767
+ ```
768
+
769
+ ### forwardMessage
770
+
771
+ ```javascript
772
+ var messagesIds = [2539, 2538, 2537];
773
+
774
+ chatAgent.forwardMessage({
775
+ subjectId: threadId,
776
+ content: JSON.stringify(messagesIds)
777
+ }, {
778
+ onSent: function(result) {
779
+ console.log(result.uniqueId + " \t has been Sent! (FORWARD)");
780
+ },
781
+ onDeliver: function(result) {
782
+ console.log(result.uniqueId + " \t has been Delivered! (FORWARD)");
783
+ },
784
+ onSeen: function(result) {
785
+ console.log(result.uniqueId + " \t has been Seen! (FORWARD)");
786
+ }
787
+ });
788
+ ```
789
+
790
+ ## File functions
791
+
792
+ ### sendFileMessage
793
+
794
+ ```html
795
+ <form>
796
+ <fieldset>
797
+ <legend>Send File Message</legend>
798
+ <input type="file" name="sendFileInput" id="sendFileInput">
799
+ <br>
800
+ <label for="sendFileDescription">Description: </label>
801
+ <input type="text" name="sendFileDescription" id="sendFileDescription">
802
+ <button type="button" name="button" id="sendFileMessage">Send</button>
803
+ </fieldset>
804
+ </form>
805
+ ```
806
+
807
+ ```javascript
808
+ document.getElementById("sendFileMessage").addEventListener("click", function() {
809
+ var fileInput = document.getElementById("sendFileInput"),
810
+ image = fileInput.files[0],
811
+ content = document.getElementById("sendFileDescription").value;
812
+
813
+ chatAgent.sendFileMessage({
814
+ threadId: 293,
815
+ file: image,
816
+ content: content,
817
+ metaData: {custom_name: "John Doe"}
818
+ }, {
819
+ onSent: function(result) {
820
+ console.log(result.uniqueId + " \t has been Sent!");
821
+ },
822
+ onDeliver: function(result) {
823
+ console.log(result.uniqueId + " \t has been Delivered!");
824
+ },
825
+ onSeen: function(result) {
826
+ console.log(result.uniqueId + " \t has been Seen!");
827
+ }
828
+ });
829
+ });
830
+ ```
831
+
832
+ ### cancelFileUpload
833
+
834
+ If you want to cancel sending of the message with a file upload, You can get uploading file's uniqueId
835
+ immediately after calling `sendFileMessage()` and send it as a parameter to `cancelFileUpload()`
836
+
837
+ ```javascript
838
+ var instantResult = chatAgent.sendFileMessage({
839
+ threadId: 293,
840
+ file: image,
841
+ content: content
842
+ }, {
843
+ onSent: function(result) {},
844
+ onDeliver: function(result) {},
845
+ onSeen: function(result) {}
846
+ });
847
+
848
+ chatAgent.cancelFileUpload({
849
+ uniqueId: instantResult.content.file.uniqueId
850
+ }, function() {
851
+ console.log("File Upload has been Canceled!");
852
+ });
853
+ ```
854
+
855
+ ### uploadFile
856
+
857
+ ```html
858
+ <form>
859
+ <fieldset>
860
+ <legend>Upload File</legend>
861
+ <input type="file" name="file" id="fileInput" value="">
862
+ <button type="button" name="button" id="uploadFile">Upload File</button>
863
+ <br>
864
+ <div id="uploadedFile"></div>
865
+ </fieldset>
866
+ </form>
867
+ ```
868
+
869
+ ```javascript
870
+ document.getElementById("uploadFile").addEventListener("click", function() {
871
+ var fileInput = document.getElementById("fileInput"),
872
+ file = fileInput.files[0];
873
+
874
+ chatAgent.uploadFile({
875
+ file: file,
876
+ fileName: "Test Name"
877
+ }, function(result) {
878
+ if (!result.hasError) {
879
+ var file = result.result;
880
+ document.getElementById("uploadedFile").innerHTML = "<pre><br>Uploaded File Id: " + file.id + "<br>Uploaded File Name : " + file.name + "<br>Uploaded File HashCode : " + file.hashCode + "</pre>";
881
+ }
882
+ });
883
+ });
884
+ ```
885
+
886
+ ### uploadImage
887
+
888
+ ```html
889
+ <form>
890
+ <fieldset>
891
+ <legend>Upload Image</legend>
892
+ <input type="file" name="image" id="imageInput" value="">
893
+ <button type="button" name="button" id="uploadImage">Upload Image</button>
894
+ <br>
895
+ <img id="uploadedImage" />
896
+ <div id="uploadedImageData"></div>
897
+ </fieldset>
898
+ </form>
899
+ ```
900
+
901
+ ```javascript
902
+ document.getElementById("uploadImage").addEventListener("click", function() {
903
+ var imageInput = document.getElementById("imageInput"),
904
+ image = imageInput.files[0];
905
+
906
+ chatAgent.uploadImage({
907
+ image: image,
908
+ fileName: "Test Name",
909
+ xC: 0,
910
+ yC: 0,
911
+ hC: 800,
912
+ wC: 800
913
+ }, function(result) {
914
+ if (!result.hasError) {
915
+ var image = result.result;
916
+ document.getElementById("uploadedImage").src = "http://172.16.106.26:8080/hamsam/nzh/image?imageId=" + image.id + "&hashCode=" + image.hashCode;
917
+ document.getElementById("uploadedImageData").innerHTML = "<pre><br>Uploaded Image Id: " + image.id + "<br>Uploaded Image Name : " + image.name + "<br>Uploaded Image HashCode : " + image.hashCode + "</pre>";
918
+ }
919
+ });
920
+ });
921
+ ```
922
+
923
+ ### getFile
924
+
925
+ ```javascript
926
+ chatAgent.getFile({
927
+ fileId: fileId,
928
+ hashCode: hashCode,
929
+ downloadable: true
930
+ }, function(result) {
931
+ if (!result.hasError) {
932
+ var file = result.result;
933
+ }
934
+ });
935
+ ```
936
+
937
+ ### getImage
938
+
939
+ ```javascript
940
+ chatAgent.getImage({
941
+ imageId: imageId,
942
+ hashCode: hashCode,
943
+ downloadable: true,
944
+ actual: true
945
+ }, function(result) {
946
+ if (!result.hasError) {
947
+ var image = result.result;
948
+ }
949
+ });
950
+ ```
951
+
952
+ ## System Messages
953
+
954
+ ### isTyping
955
+ To indicate that some one is currently typing in some specific thread, you can use `startTyping()` and `stopTyping()`
956
+
957
+ #### startTyping
958
+ This function sets an interval and sends `isTyping` system message to server every 1 second
959
+
960
+ ```javascript
961
+ /**
962
+ * Sending isTyping message to server with an interval of 1 sec
963
+ *
964
+ * @param {int} threadId Id of thread that user is typing in
965
+ */
966
+
967
+ chatAgent.startTyping({
968
+ threadId: 1431
969
+ });
970
+ ```
971
+
972
+ #### stopTyping
973
+ Because user can only type in one thread at time, so there will be only one isTypingInterval available. This function
974
+ clears it and stops sending the system messages.
975
+
976
+ ```javascript
977
+ /**
978
+ * Stops Sending isTyping message to server
979
+ */
980
+
981
+ chatAgent.stopTyping();
982
+ ```
983
+
984
+
985
+ ## Embedded Map Service functions
986
+
987
+ ### mapReverse
988
+
989
+ This function takes a Geo Location and returns its address back
990
+
991
+ ```javascript
992
+ /**
993
+ * Get Address of a GeoLocation point
994
+ *
995
+ * @param {float} lat Latitute of the Location
996
+ * @param {float} lng Longtitute of the Location
997
+ */
998
+ chatAgent.mapReverse({
999
+ lat: 35.7003508,
1000
+ lng: 51.3376460
1001
+ }, function(result) {
1002
+ console.log(result);
1003
+ });
1004
+ ```
1005
+
1006
+ ### mapSearch
1007
+
1008
+ This function takes a Geo Location and a Search term and returns an array of Nearby places containing that search term
1009
+
1010
+ ```javascript
1011
+ /**
1012
+ * Get nearby places names as "term" keyword
1013
+ * around the given GeoLocation
1014
+ *
1015
+ * @param {float} lat Latitute of the Location
1016
+ * @param {float} lng Longtitute of the Location
1017
+ * @param {string} term Search term to be searched
1018
+ */
1019
+ chatAgent.mapSearch({
1020
+ lat: 35.7003508,
1021
+ lng: 51.3376460,
1022
+ term: "فروشگاه"
1023
+ }, function(result) {
1024
+ console.log(result);
1025
+ });
1026
+ ```
1027
+
1028
+ ### mapRouting
1029
+
1030
+ This function takes two Geo Locations and returns the route between them
1031
+
1032
+ ```javascript
1033
+ /**
1034
+ * Get routing between two given GeoLocations
1035
+ *
1036
+ * @param {object} origin Lat & Lng of Origin as a JSON
1037
+ * @param {object} destination Lat & Lng of Destination as a JSON
1038
+ * @param {boolean} alternative Give Alternative Routs too
1039
+ */
1040
+ chatAgent.mapRouting({
1041
+ origin: {
1042
+ lat: 35.7003508,
1043
+ lng: 51.3376460
1044
+ },
1045
+ destination: {
1046
+ lat: 35.7343510,
1047
+ lng: 50.3376472
1048
+ },
1049
+ alternative: true
1050
+ }, function(result) {
1051
+ console.log(result);
1052
+ });
1053
+ ```
1054
+
1055
+ ### mapStaticImage
1056
+
1057
+ This function takes a Geo Locations and returns the link of static map image related that area
1058
+
1059
+ ```javascript
1060
+ /**
1061
+ * Get Static Image of a GeoLocation
1062
+ *
1063
+ * @param {string} type Map style (default standard-night)
1064
+ * @param {int} zoom Map zoom (default 15)
1065
+ * @param {object} center Lat & Lng of Map center as a JSON
1066
+ * @param {int} width width of image in pixels (default 800px)
1067
+ * @param {int} height height of image in pixels (default 600px)
1068
+ */
1069
+ chatAgent.mapStaticImage({
1070
+ type: "standard-night",
1071
+ zoom: 15,
1072
+ center: {
1073
+ lat: 35.7003508,
1074
+ lng: 51.3376462
1075
+ },
1076
+ width: 800,
1077
+ height: 500
1078
+ }, function(result) {
1079
+ console.log(result);
1080
+ });
1081
+ ```
1082
+
1083
+ ## Installation
1084
+
1085
+ ```javascript
1086
+ npm install podchat --save
1087
+ ```
1088
+
1089
+ ## API Reference
1090
+
1091
+ [API Docs from POD](http://docs.pod.land/v1.0.0.0/Chat/javascript/783/Introduction)
1092
+
1093
+ ## Tests
1094
+
1095
+ ```javascript
1096
+ npm test
1097
+ ```
1098
+
1099
+ ## Contributors
1100
+
1101
+ You can send me your thoughts about making this repo great :)
1102
+ [Email](masoudmanson@gmail.com)
1103
+
1104
+ ## License
1105
+
1106
+ Under MIT License.
1107
+
1108
+ ## Acknowledgments
1109
+
1110
+ A very special thanks to Ali Khanbabaei ([khanbabaeifanap](https://github.com/khanbabaeifanap)), who wrote the early version of chat service and helped me a lot with this repo.