-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateTextConversation.js
60 lines (48 loc) · 2.19 KB
/
generateTextConversation.js
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
const {AmoJoScopeClient, AmoApiClient} = require('../../dist');
const {
debug,
scopeId,
channelSecret,
domain,
accessToken,
amojoUserId,
channelBotId,
} = require('../_config');
const amoJoScopeClient = new AmoJoScopeClient({scopeId, channelSecret, debug});
const amoApiClient = new AmoApiClient(domain, accessToken, {debug});
const contactId = 4312867;
const sourceExternalId = 'channelu64pwcou';
async function start () {
// создаем чат
const chatDto = amoJoScopeClient.getChatDto(amojoUserId);
console.log('chatDto', chatDto);
const chat = await amoJoScopeClient.createChat(chatDto);
console.log('chat', chat);
// прикрепляем чат к контакту
const attach = await amoApiClient.attachChatToContact(chat.id, contactId);
console.log('attach', JSON.stringify(attach));
// текстовое сообщение от пользователя контакту
const conversationId = chat.id;
const message1 = amoJoScopeClient.getTextPayloadFromUser({
conversationId, amojoUserId, message: 'from user text message', sourceExternalId});
console.log('message', message1);
// отправляем сообщение в чат
const response1 = await amoJoScopeClient.sendMessage(message1);
const msgid1 = response1.new_message.msgid;
console.log('response', response1, msgid1);
// текстовое сообщение от бота контакту
const message2 = amoJoScopeClient.getTextPayloadFromBot({
conversationId, channelBotId, message: 'from bot text message', sourceExternalId});
console.log('message', message2);
const response2 = await amoJoScopeClient.sendMessage(message2);
const msgid2 = response2.new_message.msgid;
console.log('response', response2, msgid2);
// текстовое сообщение от контакта в сделку
const message3 = amoJoScopeClient.getTextPayloadFromContact({
conversationId, senderName: 'Сергей', message: 'from contact text message', sourceExternalId});
console.log('message', message3);
const response3 = await amoJoScopeClient.sendMessage(message3);
const msgid3 = response3.new_message.msgid;
console.log('response', response3, msgid3);
}
(start)();