-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
63 lines (55 loc) · 1.58 KB
/
example.js
File metadata and controls
63 lines (55 loc) · 1.58 KB
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
59
60
61
62
63
// In your project it would be requiring 'error-shout-bot'
var errorShout = require('./index.js');
// Reading in token and chatId from environment variables
var botToken = process.env.ERROR_SHOUT_BOT_TOKEN;
var chatId = process.env.ERROR_SHOUT_CHAT_ID;
// chatId can be a chatID, GroupID or a channel (e.g @channelName)
// Make sure the bot is authorized to post in the configured place
var Shout = new errorShout(botToken, chatId);
// getBotName - This can be used to log the name of the bot that is configured
Shout.getBotName()
.then(function(name) {
/* eslint-disable no-console */
console.log(name);
/* eslint-disable no-console */
});
// sendError - Example of a simple message
Shout.sendError('Oh No, something happened');
// sendError - Example of a message with a source and methodName inside a catch
try {
var testVar = null;
testVar.doSomething();
} catch (error) {
Shout.sendError(error, 'error-shout-bot example', 'doSomething', 'This is showing an error in a catch');
}
// showing that markdown characters get escaped
Shout.sendError('SH*OU`T_ it out!');
// sending an error using an Object
Shout.sendError({ message: 'this is an error object'});
Shout.sendError({
message: 'An error with a complex object',
error: {
levelOne: {
levelTwo: {
levelThree: {
usefulInfo: '1+1=2'
}
}
}
}
});
Shout.sendError({
message: 'An error with a complex object',
error: {
levelOne: {
levelTwo: {
levelThree: {
usefulInfo: '1+1=2'
}
}
}
},
anyRandomKey: 'meow',
number: 123,
boolean: false
});