diff --git a/include/config/config.xml b/include/config/config.xml
index 60cf1a227..d54f8e71b 100755
--- a/include/config/config.xml
+++ b/include/config/config.xml
@@ -87,10 +87,10 @@
***REMOVED***
- _PHONE_
+
diff --git a/include/controllers/default/crunchbutton/api/support/index.php b/include/controllers/default/crunchbutton/api/support/index.php
index 3376a0188..c1db6a8af 100644
--- a/include/controllers/default/crunchbutton/api/support/index.php
+++ b/include/controllers/default/crunchbutton/api/support/index.php
@@ -9,12 +9,20 @@ class Controller_api_Support extends Crunchbutton_Controller_Rest {
if (c::getPagePiece(2) == 'sms') {
+
+ // Create a twilio session
+ $tsess = new Session_Twilio;
+ $tsess->phone = $this->request()['phone'];
+ $tsess->data = json_encode( $_REQUEST );
+ $tsess->save();
+
$support = new Crunchbutton_Support;
$support->type = 'sms';
$support->name = $this->request()['name'];
$support->phone = $this->request()['phone'];
$support->message = $this->request()['message'];
$support->ip = $_SERVER['REMOTE_ADDR'];
+ $support->id_session_twilio = $tsess->id_session_twilio;
$support->date = date('Y-m-d H:i:s');
if( c::user()->id_user ){
$support->id_user = c::user()->id_user;
diff --git a/include/library/Crunchbutton/Support.php b/include/library/Crunchbutton/Support.php
index 97723eb86..9a3f529d1 100644
--- a/include/library/Crunchbutton/Support.php
+++ b/include/library/Crunchbutton/Support.php
@@ -38,18 +38,7 @@ class Crunchbutton_Support extends Cana_Table {
// Log
Log::debug( [ 'action' => 'support', 'message' => $message, 'type' => 'support' ] );
- $data = [ 'request' => $_REQUEST, 'support' => json_decode( $this->json() ) ];
-
- // Create a twilio session
- $tsess = new Session_Twilio;
- $tsess->phone = $this->phone;
- $tsess->data = json_encode( $data );
- $tsess->save();
-
- $this->id_session_twilio = $tsess->id_session_twilio;
- $this->save();
-
- $message = '@'.$tsess->id_session_twilio.' : ' . $message;
+ $message = '@'.$this->id_session_twilio.' : ' . $message;
$message = str_split( $message, 160 );
// Send this message to the customer service
@@ -58,7 +47,7 @@ class Crunchbutton_Support extends Cana_Table {
foreach ($message as $msg) {
try {
// Log
- Log::debug( [ 'action' => 'sending sms - support', 'session id' => $tsess->id_session_twilio, 'num' => $num, 'msg' => $msg, 'type' => 'support' ] );
+ Log::debug( [ 'action' => 'sending sms - support', 'session id' => $this->id_session_twilio, 'num' => $num, 'msg' => $msg, 'type' => 'support' ] );
$twilio->account->sms_messages->create(
c::config()->twilio->{$env}->outgoingTextCustomer,
'+1'.$num,
@@ -66,7 +55,7 @@ class Crunchbutton_Support extends Cana_Table {
);
} catch (Exception $e) {
// Log
- Log::debug( [ 'action' => 'ERROR sending sms - support', 'session id' => $tsess->id_session_twilio, 'num' => $num, 'msg' => $msg, 'type' => 'sms' ] );
+ Log::debug( [ 'action' => 'ERROR sending sms - support', 'session id' => $this->id_session_twilio, 'num' => $num, 'msg' => $msg, 'type' => 'sms' ] );
}
}
}