UNPKG

2.97 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3/**
4 * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
5 *
6 * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
7 * Wechaty Contributors <https://github.com/wechaty>.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 */
22Object.defineProperty(exports, "__esModule", { value: true });
23/* eslint-disable import/first */
24require('dotenv').config();
25const config_1 = require("../src/config");
26const io_client_1 = require("../src/io-client");
27const wechaty_1 = require("../src/wechaty");
28const welcome = `
29| __ __ _ _
30| \\ \\ / /__ ___| |__ __ _| |_ _ _
31| \\ \\ /\\ / / _ \\/ __| '_ \\ / _\` | __| | | |
32| \\ V V / __/ (__| | | | (_| | |_| |_| |
33| \\_/\\_/ \\___|\\___|_| |_|\\__,_|\\__|\\__, |
34| |___/
35
36=============== Powered by Wechaty ===============
37 -------- https://www.chatie.io --------
38
39My super power: download cloud bot from www.chatie.io
40
41__________________________________________________
42
43`;
44async function main() {
45 const token = config_1.config.token;
46 if (!token) {
47 throw new Error('token not found: please set WECHATY_TOKEN in environment before run io-client');
48 }
49 console.info(welcome);
50 config_1.log.info('Client', 'Starting for WECHATY_TOKEN: %s', token);
51 const wechaty = new wechaty_1.Wechaty({ name: token });
52 let port;
53 if (process.env['WECHATY_HOSTIE_PORT']) {
54 /**
55 * https://github.com/wechaty/wechaty/issues/2122
56 */
57 config_1.log.warn('Wechaty', [
58 '',
59 'WECHATY_HOSTIE_PORT is deprecated.',
60 'Use WECHATY_PUPPET_SERVER_PORT instead.',
61 'See: https://github.com/wechaty/wechaty/issues/2122',
62 ].join(' '));
63 port = parseInt(process.env['WECHATY_HOSTIE_PORT']);
64 }
65 else if (process.env['WECHATY_PUPPET_SERVER_PORT']) {
66 port = parseInt(process.env['WECHATY_PUPPET_SERVER_PORT']);
67 }
68 const options = {
69 token,
70 wechaty,
71 };
72 if (port) {
73 options.port = port;
74 }
75 const client = new io_client_1.IoClient(options);
76 client.start()
77 .catch(onError.bind(client));
78}
79async function onError(e) {
80 config_1.log.error('Client', 'start() fail: %s', e);
81 await this.quit();
82 process.exit(-1);
83}
84main()
85 .catch(console.error);
86//# sourceMappingURL=io-client.js.map
\No newline at end of file