1 | import superscript from 'superscript';
|
2 | import xmpp from 'simple-xmpp';
|
3 |
|
4 | const receiveData = function receiveData(from, bot, data) {
|
5 |
|
6 | let message = `${data}`;
|
7 |
|
8 | message = message.replace(/[\x0D\x0A]/g, '');
|
9 |
|
10 | bot.reply(from, message.trim(), (err, reply) => {
|
11 | xmpp.send(from, reply.string);
|
12 | });
|
13 | };
|
14 |
|
15 |
|
16 | const botHandle = function botHandle(err, bot) {
|
17 | xmpp.connect({
|
18 | jid: 'EMAIL ADRESS',
|
19 | password: 'PASSWORD',
|
20 | host: 'talk.google.com',
|
21 | port: 5222,
|
22 | reconnect: true,
|
23 | });
|
24 |
|
25 | xmpp.on('online', (data) => {
|
26 | console.log(`Connected with JID: ${data.jid.user}`);
|
27 | console.log('Yes, I\'m connected!');
|
28 | });
|
29 |
|
30 | xmpp.on('chat', (from, message) => {
|
31 | receiveData(from, bot, message);
|
32 | });
|
33 |
|
34 | xmpp.on('error', (err) => {
|
35 | console.error(err);
|
36 | });
|
37 | };
|
38 |
|
39 |
|
40 | const options = {
|
41 | factSystem: {
|
42 | clean: true,
|
43 | },
|
44 | importFile: './data.json',
|
45 | };
|
46 |
|
47 | superscript.setup(options, (err, bot) => {
|
48 | botHandle(null, bot);
|
49 | });
|