/
chat-service.ts
58 lines (52 loc) · 2.12 KB
/
chat-service.ts
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
import { MessageToContact } from '../../../js-miniapp-bridge/src';
import { getBridge } from '../utils';
interface ChatServiceProvider {
/**
* Opens a contact chooser which allows the user to choose a single contact,
* and then sends the message to the chosen contact.
* @param message The message to send to contact.
* @returns Promise resolves with the contact id received a message.
* Can also resolve with null response in the case that the message was not sent to a contact, such as if the user cancelled sending the message.
* Promise rejects in the case that there was an error.
*/
sendMessageToContact(message: MessageToContact): Promise<string | null>;
/**
* Send a message to the specific contact.
* @param id The id of the contact receiving a message.
* @param message The message to send to contact.
* @returns Promise resolves with the contact id received a message.
* @see {sendMessageToContact}
*/
sendMessageToContactId(
id: string,
message: MessageToContact
): Promise<string | null>;
/**
* Opens a contact chooser which allows the user to choose a multiple contacts
* and then sends the message to the all chosen contacts.
* @param message The message to send to contact.
* @returns Promise resolves with an array of contact id which were sent the message.
* Can also resolve with null array in the case that the message was not sent to any contacts, such as if the user cancelled sending the message.
* Promise rejects in the case that there was an error.
*/
sendMessageToMultipleContacts(
message: MessageToContact
): Promise<string[] | null>;
}
/** @internal */
export class ChatService {
sendMessageToContact(message: MessageToContact): Promise<string | null> {
return getBridge().sendMessageToContact(message);
}
sendMessageToContactId(
id: string,
message: MessageToContact
): Promise<string | null> {
return getBridge().sendMessageToContactId(id, message);
}
sendMessageToMultipleContacts(
message: MessageToContact
): Promise<string[] | null> {
return getBridge().sendMessageToMultipleContacts(message);
}
}