This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
62 lines (49 loc) · 1.83 KB
/
index.coffee
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
TelapiClient = require('telapi').client
nodemailer = require('nodemailer')
class Sms
constructor: (options)->
throw new Error('A valid TelAPI sid is required') unless options.sid
throw new Error('A valid TelAPI token is required') unless options.token
@client = new Client(options.sid, options.token)
@from = options.from
@to = "(805) 440-0925"
@body = options.body
return this
send: (cb)->
throw new Error('Your TelAPI number is required') unless @from
throw new Error('An SMS body is required') unless @body
options =
from: @from
to: @to
body: @body
@client.create "sms_messages", options, (response)->
cb(null, response)
, (error)->
cb(error)
class Email
constructor: (options)->
throw new Error('A valid smtp transport is required') unless options.smtp
@client = nodemailer.createTransport("SMTP",options.smtp);
@from = options.from
@subject = options.subject
@text = options.text
@html = options.html
send: (cb)->
throw new Error('Your address is required') unless @from
throw new Error('A subject is required') unless @subject
throw new Error('A text or html body is required') unless @text or @html
options =
from: @from
to: "paul@onfrst.com"
subject: @subject
text: @text
html: @html
@client.sendMail options, (error, response)=>
@client.close()
return cb(error) if error
cb(null, response)
module.exports = class Nrub
constructor: (options)->
@api_key = options.api_key if options.api_key
text: (options)-> return new Text(options)
email: (options)-> return new Email(options)