Tutorials
SENDING SMS
This method provides a way to receive Egosms Transaction Status delivery report via JSON
Requirement
Procedure
In your application, create a path (DLR URL) to listen and capture json data as below;
{“MsgFollowUpUniqueCode”: “ApiJsonSubmit64b8dd8aab0d05.55176607″,”number”: “+256777071434″,”Status”: “Success”}
Capturing DLR URL Code Example
Setting up Egosms Account to receive transaction status delivery report
Steps
Everything is now set up.
How To Use
Log into your system and send a message.
System Feedback
The Following Transaction Status Report including status, cost and MsgFollowUpUniqueCode will be received
SMS Delivered report
{"MsgFollowUpUniqueCode": "ApiJsonSubmit64b8dd8aab0d05.55176607","number": "+256777071434","Status": "Success"}
Saving SMS Delivered report into the database code PHP Example
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Read the raw data from the incoming HTTP request's body
$data = file_get_contents("php://input");
// Decode the JSON data into an associative array
$decoded_data = json_decode($data, true);
//put data to the msgdata.txt
file_put_contents('msgdata.txt', $data, FILE_APPEND);
// Check if JSON decoding was successful
if ($decoded_data === null) {
echo "Error decoding JSON data.";
exit;
}
// Extract data from the new JSON structure
$number = $decoded_data['number'];
$message_code = $decoded_data['MsgFollowUpUniqueCode'];
$status = $decoded_data['Status'];
// Escape each value to prevent SQL injection
$number = $conn->real_escape_string($number);
$message_code = $conn->real_escape_string($message_code);
$status = $conn->real_escape_string($status);
// SQL query to insert the data into a table named 'egosmsdata'
$sql = "INSERT INTO tableName (number, message_code, status) VALUES ('$number', '$message_code', '$status')";
if ($conn->query($sql) !== TRUE) {
echo "Error in saving delivery report: " . $conn->error;
$conn->close();
exit;
}
echo "Delivery report saved successfully into the database.";
// Close the database connection
$conn->close();
?>
Capturing DLR URL Code Examples
$data=file_get_contents("php://input");
file_put_contents(msg_details.txt',$data,FILE_APPEND);
echo “ok, msg delivered”;
def save_message_to_file(data):
with open("msg_details.txt", "a") as file:
file.write(data + "\n")
def main():
data = input()
save_message_to_file(data)
print("ok, msg delivered")
if __name__ == "__main__":
main()
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void saveMessageToFile(String data, String filename) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) {
writer.write(data + "\n");
}
}
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String data = reader.readLine().trim();
reader.close();
if (!data.isEmpty()) { saveMessageToFile(data, "msg_details.txt");
System.out.println("ok, msg delivered");
} else {
System.out.println("Error: No data received.");
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
require 'net/http'
url = URI.parse('http://your-server.com/msg_details.txt')
data = Net::HTTP.get(url)
File.open('msg_details.txt', 'a') do |file|
file.puts(data)
end
puts 'ok, msg delivered'
using System;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace YourNamespace.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class YourController : ControllerBase
{
[HttpPost]
public IActionResult Post()
{
string data = ReadDataFromRequest();
SaveDataToFile(data);
return Ok("ok, msg delivered");
}
private string ReadDataFromRequest()
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
private void SaveDataToFile(string data)
{
string filePath = "msg_details.txt";
File.AppendAllText(filePath, data, Encoding.UTF8);
}
}
}
$data=file_get_contents("php://input");
file_put_contents(msg_details.txt',$data,FILE_APPEND);
echo “ok, msg delivered”;
def save_message_to_file(data):
with open("msg_details.txt", "a") as file:
file.write(data + "\n")
def main():
data = input()
save_message_to_file(data)
print("ok, msg delivered")
if __name__ == "__main__":
main()
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void saveMessageToFile(String data, String filename) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) {
writer.write(data + "\n");
}
}
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String data = reader.readLine().trim();
reader.close();
if (!data.isEmpty()) { saveMessageToFile(data, "msg_details.txt");
System.out.println("ok, msg delivered");
} else {
System.out.println("Error: No data received.");
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
require 'net/http'
url = URI.parse('http://your-server.com/msg_details.txt')
data = Net::HTTP.get(url)
File.open('msg_details.txt', 'a') do |file|
file.puts(data)
end
puts 'ok, msg delivered'
using System;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace YourNamespace.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class YourController : ControllerBase
{
[HttpPost]
public IActionResult Post()
{
string data = ReadDataFromRequest();
SaveDataToFile(data);
return Ok("ok, msg delivered");
}
private string ReadDataFromRequest()
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
private void SaveDataToFile(string data)
{
string filePath = "msg_details.txt";
File.AppendAllText(filePath, data, Encoding.UTF8);
}
}
}
Egosms Documentation
Tutorials
SENDING SMS