bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
Support.scala
(1617B)
1 package inc.pyc.chimera
2 package minions
3
4 import lib._
5 import xml._
6 import akka.actor._
7 import net.liftweb._
8 import http._
9 import common._
10 import util._
11 import Helpers._
12 import System._
13
14 class CustomerSupportMinion
15 extends Actor
16 with ActorLogging
17 with Minion {
18
19 val tasks: Receive = {
20 case (email: Email, tx: IncompleteTx) => send(email, tx)
21 case (phone: Phone, tx: IncompleteTx) => send(phone, tx)
22 }
23
24 /**
25 * Creates Transaction Receipt HTML message.
26 */
27 def create(tx: IncompleteTx): Box[NodeSeq] = {
28 Templates("templates-hidden" :: "email" :: "support" :: Nil) map {
29 ".fname" #> name(tx) &
30 ".txaddress" #> tx.address &
31 ".txamount" #> tx.prettyTotal &
32 ".txbtc" #> tx.bitcoins &
33 ".txdate" #> tx.prettyDate &
34 ".txtime" #> tx.prettyTime &
35 ".txlocation" #> Settings(system).name &
36 ".tech-phone" #> Settings(system).techPhone
37 }
38 }
39
40 /**
41 * Sends Transaction Receipt message.
42 */
43 def send(email: Email, tx: IncompleteTx): Unit = {
44 create(tx) foreach {
45 html =>
46 lib.Mailer(email.data,
47 "PYC Customer Support", html.toString)
48 }
49 }
50
51 def send(phone: Phone, tx: IncompleteTx): Unit = {
52 if(phone.sms) {
53 val msg = "Hi %s, PYC will revise your bitcoin transaction of %s and "+
54 "contact you shortly. Feel free to call tech support at %s. Sorry for"+
55 " the trouble." format (name(tx), tx.prettyTotal, Settings(system).techPhone)
56
57 val sent = Twilio.sms(phone.number, msg)
58 }
59 }
60
61 def name(tx: IncompleteTx) = tx.userInfo.fname getOrElse ""
62 }