====== How to send SMS via a 3rd party platform ====== ===== How SMS work in asterCC ===== * When you write SMS text and click [Send] button in asterCC, the system would save the message in table cc10_batchcontacts and cc10_batchcontact_archives. * Next, you need program a file and read the SMS record from database, send the message to the third party server by the request of the third party platform. * Finally, according to the return value from the third party, update the status value of the SMS data in the system, and mark if it has been sent successfully. ===== Data sheet ==== * Sheet cc10_batchcontacts save the target phone number, sender’s account, and send status. * batchcontact_archive_id,Relate the data id of sheet cc10_batchcontact_archives to batchcontact_archive_id and the latter is for save the specific text of SMS. * target,The phone number of receivers. * status,The send status of SMS. * The original status is “new”, means a new one to be sent. And you system needs SMS like this and send them. * Once the SMS is being sending, please change the value into “pending” in the system. * When it is sent, change the status into “error”, “failed” or “success” according to the third party return value. * schedulertime,Preset the sending time, “0000-00-00 00:00:00”maens sending right now. And you can also set the sending time. The system would search the data field that is less than this time. * contacttime,The time to push the SMS to the third party. You can update the status field and the return value after the latter is been returned by the third party. * creby,The account of the SMS creator. * created,The time of the SMS’s creation. * error_msg,Add the reason here when the message sending result in failure or meet error. * responsenote,The reply message from the receiver, provided by the third party. When the system received the message, you can update in this field. * Sheet cc10_batchcontact_archives saves the actual text of the SMS to be sent. * Sheet cc10_batchcontacts relates the data within itself via the field “batchcontact_archive_id”. * archivetype: The message type. * content: The content of the SMS ===== php code demonstration ==== * create a sms.php file, this demonstration is using a third party http API to send SMS. PHP code screenshot is on the below: * define variables {{:zh:二次开发者指南:如何使用第三方短信平台发送短信_定义变量.jpg?768}} * Inquire the SMS to be sent from database, call function to send, and update the third party return value {{:zh:二次开发者指南:如何使用第三方短信平台发送短信_处理数据.jpg?768}} * define the sending method {{:zh:二次开发者指南:如何使用第三方短信平台发送短信_发送方法.jpg?768}} * set the execution cycle of this script * if you want to perform it every minute, you can add this file into “crontab -e” put “* * * * *”means perform it every minute. {{:zh:二次开发者指南:如何使用第三方短信平台发送短信_执行周期.jpg}} * You can also make an infinite loops in the coding, and execute this php file in the server, making the program searching for the new SMS ceaselessly. {{:zh:二次开发者指南:如何使用第三方短信平台发送短信_执行周期2.jpg?768}} * of course, you can execute this program through other ways. Just make sure you can find out the new SMS and send them to the third party server. ===== test the SMS sending in the system ==== * login the agent platform, click the button to send SMS. {{:en:custom_development_guide:发送消息界面.jpg}} * Make sure it is the right message and click send, you will get the following tip: {{:en:custom_development_guide:发送提示.jpg}} * For the SMS to be sent and the failed ones, you can check them in Messages -> Batchcontact {{:en:custom_development_guide:待发信息管理.jpg?768}} * If the SMS has been sent successfully, you can check them in Messages -> Batchcontact Sent {{:en:custom_development_guide:已发信息管理.jpg?768}}