-
Notifications
You must be signed in to change notification settings - Fork 0
/
ambient_sms_gateway.inbound.inc
51 lines (40 loc) · 1.46 KB
/
ambient_sms_gateway.inbound.inc
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
<?php
class ambientInboundSms {
public $transaction;
public $id;
public $sender;
public $destination;
public $message;
public $in_reply_to;
public $received_at;
public $options;
function __construct($sender, $destination, $message, $received_at, $in_reply_to, $conf) {
$this->sender = $sender;
$this->destination = $destination;
$this->message = $message;
$this->received_at = $received_at;
$this->in_reply_to = $in_reply_to;
//Configuration
$this->options = $conf['options'];
//Transaction log
$this->transaction = new stdClass();
}
static function parseInbound() {
$POST = file_get_contents("php://input");
// msisdn=27826941134&shortcode=2782007210000006&keyword=Hi&msg=Hi+dude&message_id=1
$ret = new ambientInboundSms($_POST['msisdn'], $_POST['shortcode'], $_POST['msg'], time(), $_POST['message_id'], array());
$ret->transaction->request = $POST;
return $ret;
}
function logTransaction() {
if($this->id) {
drupal_write_record("ambient_sms_gateway_inbox", $this, "id");
drupal_write_record("ambient_sms_gateway_inbox_transaction", $this->transaction, "id");
} else {
drupal_write_record("ambient_sms_gateway_inbox", $this);
//Set the transaction id if it isnt yet set
if($this->id && !$this->transaction->id) { $this->transaction->id = $this->id; }
drupal_write_record("ambient_sms_gateway_inbox_transaction", $this->transaction);
}
}
}