MCPcopy
hub / github.com/typpo/textbelt / textRequestHandler

Function textRequestHandler

server/app.js:29–66  ·  view source on GitHub ↗
(req, res, number, carrier, region)

Source from the content-addressed store, hash-verified

27}
28
29function textRequestHandler(req, res, number, carrier, region) {
30 if (!number || !req.body.message) {
31 res.send({ success: false, message: 'Number and message parameters are required.' });
32 return;
33 }
34
35 let carrierKey = null;
36 if (carrier) {
37 carrierKey = carrier.toLowerCase();
38 if (carriers[carrierKey] == null) {
39 res.send({
40 success: false,
41 message: `Carrier ${carrier} not supported! POST getcarriers=1 to `
42 + 'get a list of supported carriers',
43 });
44 return;
45 }
46 }
47
48 let { message } = req.body;
49 if (message.indexOf(':') > -1) {
50 // Handle problem with vtext where message would not get sent properly if it
51 // contains a colon.
52 message = ` ${message}`;
53 }
54
55 // Time to actually send the message
56 text.send(number, message, carrierKey, region, (err) => {
57 if (err) {
58 res.send({
59 success: false,
60 message: `Communication with SMS gateway failed. Did you configure mail transport in lib/config.js? Error message: '${err.message}'`,
61 });
62 } else {
63 res.send({ success: true });
64 }
65 });
66}
67
68// App routes
69app.get('/', (req, res) => {

Callers 1

app.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected