အကြောင်းအရာသို့ ကရန်

မက်ဆေ့ချ် ပြောင်းလွဲမှုများ

အမည်များ၊ URL များနှင့် စိတ်ကြိုက်တန်ဖိုးများကဲ့သို့ ပြောင်းလဲနေသော အကြောင်းအရာများဖြင့် ကာစကိတ်စာများကို စိတ်ကြိုက်ပြင်ဆင်ရန် ကိန်းရှင်များကို အသုံးပြုပါ။

ခြုံငုံသုံးသပ်ချက်

ကိန်းရှင်များကို ဖွင့်ရန်-

  • Personalization- လက်ခံသူအမည်များ၊ အကောင့်နံပါတ်များ ထည့်ပါ။
  • Dynamic URLs- လက်ခံသူတိုင်းအတွက် သီးသန့်လင့်ခ်များ ထည့်သွင်းပါ။
  • URL အတိုချုံးခြင်း- ရှည်လျားသော URL များကို အလိုအလျောက် အတိုချုံးပါ။
  • Template ပြန်သုံးနိုင်မှု- နမူနာပုံစံတစ်ခု၊ စိတ်ကြိုက်စာတိုများစွာ

ပြောင်းလဲနိုင်သောအမျိုးအစားများ

ရိုက် အထားအသို ရည်ရွယ်ချက် ဥပမာ
အမည် %name=id% စာသားပြောင်းလွဲများ အမည်များ၊ ကုဒ်များ၊ ပမာဏများ
url %url=id% URL အပြည့်အစုံ လင့်ခ်များ၊ URL များကို ခြေရာခံခြင်း
short_url %short_url=id% အတိုချုံ့ထားသော URLs ကျစ်လစ်သောလင့်များ

Variable Syntax

ကိန်းရှင်များသည် ဖော်မတ်- %type=id% ကို အသုံးပြုသည်။

  • အမျိုးအစား- ပြောင်းလဲနိုင်သော အမျိုးအစား (အမည်urlshort_url)
  • id- သီးသန့်သတ်မှတ်မှု (ကိန်းပြည့်)

ဥပမာများ

Hello %name=1%, your code is %name=2%
Visit our website: %url=1%
Quick link: %short_url=1%

Variable များကိုအသုံးပြုခြင်း။

အဆင့် 1- ပြောင်းလဲနိုင်သောတန်ဖိုးများကို အပ်လုဒ်လုပ်ပါ။

မက်ဆေ့ချ်များ မပို့မီ၊ API သို့ ပြောင်းလဲနိုင်သော တန်ဖိုးများကို အပ်လုဒ်လုပ်ပါ-

အဆုံးမှတ်-

POST https://restapi.smsbat.com/api/items

တောင်းဆိုချက်

{
  "variables": [
    {
      "id": 1,
      "type": "name",
      "value": "John"
    },
    {
      "id": 2,
      "type": "name",
      "value": "12345"
    },
    {
      "id": 3,
      "type": "url",
      "value": "https://example.com/products"
    },
    {
      "id": 4,
      "type": "short_url",
      "value": "https://example.com/very-long-url-that-needs-shortening"
    }
  ]
}

အဆင့် 2- Variable များဖြင့် Message ပို့ပါ။

သင့်မက်ဆေ့ဂျ်တွင် အပ်လုဒ်လုပ်ထားသော ပြောင်းလဲနိုင်သော ID များကို အသုံးပြုပါ-

{
  "id": "msg-001",
  "fromName": "YourStore",
  "toPhone": "+380XXXXXXXXX",
  "messageType": "transaction",
  "text": "Hello %name=1%! Your verification code is %name=2%. Visit: %short_url=4%"
}

ရလဒ်-

Hello John! Your verification code is 12345. Visit: https://sho.rt/abc123

ဥပမာ အပြည့်အစုံ

Variable များကို အပ်လုဒ်လုပ်ပါ။

curl -X POST https://restapi.smsbat.com/api/items \
  -H "Content-Type: application/json" \
  -H "X-Authorization-Key: your-api-key" \
  -d '{
    "variables": [
      {
        "id": 1,
        "type": "name",
        "value": "Sarah"
      },
      {
        "id": 2,
        "type": "name",
        "value": "ORD-789"
      },
      {
        "id": 3,
        "type": "url",
        "value": "https://example.com/track/ORD-789"
      }
    ]
  }'

Message ပို့ပါ။

curl -X POST https://restapi.smsbat.com/api/CascadeMessage/send_message/async \
  -H "Content-Type: application/json" \
  -H "X-Authorization-Key: your-api-key" \
  -d '[
    {
      "id": "order-notification",
      "fromName": "YourStore",
      "toPhone": "+380XXXXXXXXX",
      "messageType": "transaction",
      "text": "Hi %name=1%! Order %name=2% shipped. Track: %url=3%"
    }
  ]'

ပေးပို့ထားသော Message-

Hi Sarah! Order ORD-789 shipped. Track: https://example.com/track/ORD-789

Cases ကိုအသုံးပြုပါ။

အော်ဒါအတည်ပြုခြင်း။

// Variables
{
  "variables": [
    {"id": 1, "type": "name", "value": "John"},
    {"id": 2, "type": "name", "value": "12345"},
    {"id": 3, "type": "name", "value": "$99.99"},
    {"id": 4, "type": "url", "value": "https://store.com/order/12345"}
  ]
}

// Message
{
  "text": "Hi %name=1%! Order #%name=2% for %name=3% confirmed. Details: %url=4%"
}

// Result
"Hi John! Order #12345 for $99.99 confirmed. Details: https://store.com/order/12345"

စကားဝှက်ကို ပြန်လည်သတ်မှတ်ပါ။

// Variables
{
  "variables": [
    {"id": 1, "type": "name", "value": "Mike"},
    {"id": 2, "type": "short_url", "value": "https://app.example.com/reset?token=abc123def456"}
  ]
}

// Message
{
  "text": "Hi %name=1%, reset your password: %short_url=2% (valid 30 min)"
}

// Result
"Hi Mike, reset your password: https://sho.rt/xyz789 (valid 30 min)"

ပရိုမိုးရှင်း ကမ်ပိန်း

// Variables
{
  "variables": [
    {"id": 1, "type": "name", "value": "VIP20"},
    {"id": 2, "type": "short_url", "value": "https://store.com/sale?utm_source=sms&utm_campaign=summer"}
  ]
}

// Message
{
  "text": "Summer Sale! Use code %name=1% for 20% off: %short_url=2%"
}

// Result
"Summer Sale! Use code VIP20 for 20% off: https://sho.rt/abc"

အကောင့်အတည်ပြုခြင်း။

// Variables
{
  "variables": [
    {"id": 1, "type": "name", "value": "789456"},
    {"id": 2, "type": "name", "value": "10"}
  ]
}

// Message
{
  "text": "Your verification code: %name=1%. Valid for %name=2% minutes."
}

// Result
"Your verification code: 789456. Valid for 10 minutes."

အကောင်အထည်ဖော်မှု ဥပမာများ

Python

import requests

class CascadeVariables:
    def __init__(self, api_key):
        self.base_url = 'https://restapi.smsbat.com'
        self.headers = {
            'Content-Type': 'application/json',
            'X-Authorization-Key': api_key
        }

    def upload_variables(self, variables):
        """Upload variable values"""
        response = requests.post(
            f'{self.base_url}/api/items',
            headers=self.headers,
            json={'variables': variables}
        )
        response.raise_for_status()
        return response.json()

    def send_with_variables(self, tracking_id, from_name, to_phone,
                           message_type, text, variables):
        """Upload variables and send message"""
        # Upload variables first
        self.upload_variables(variables)

        # Send message
        message = {
            'id': tracking_id,
            'fromName': from_name,
            'toPhone': to_phone,
            'messageType': message_type,
            'text': text
        }

        response = requests.post(
            f'{self.base_url}/api/CascadeMessage/send_message/async',
            headers=self.headers,
            json=[message]
        )

        response.raise_for_status()
        return response.json()[0]

# Usage
cascade = CascadeVariables('your-api-key')

# Define variables
variables = [
    {'id': 1, 'type': 'name', 'value': 'John'},
    {'id': 2, 'type': 'name', 'value': 'ORD-12345'},
    {'id': 3, 'type': 'url', 'value': 'https://example.com/track/ORD-12345'}
]

# Send message with variables
result = cascade.send_with_variables(
    tracking_id='order-notification',
    from_name='YourStore',
    to_phone='+380XXXXXXXXX',
    message_type='transaction',
    text='Hi %name=1%! Order %name=2% shipped. Track: %url=3%',
    variables=variables
)

print(f"Message sent: {result['messageId']}")

JavaScript (Node.js)

const axios = require('axios');

class CascadeVariables {
  constructor(apiKey) {
    this.baseUrl = 'https://restapi.smsbat.com';
    this.headers = {
      'Content-Type': 'application/json',
      'X-Authorization-Key': apiKey
    };
  }

  async uploadVariables(variables) {
    const response = await axios.post(
      `${this.baseUrl}/api/items`,
      { variables },
      { headers: this.headers }
    );

    return response.data;
  }

  async sendWithVariables({ id, fromName, toPhone, messageType, text, variables }) {
    // Upload variables first
    await this.uploadVariables(variables);

    // Send message
    const response = await axios.post(
      `${this.baseUrl}/api/CascadeMessage/send_message/async`,
      [{
        id,
        fromName,
        toPhone,
        messageType,
        text
      }],
      { headers: this.headers }
    );

    return response.data[0];
  }
}

// Usage
const cascade = new CascadeVariables('your-api-key');

const result = await cascade.sendWithVariables({
  id: 'order-notification',
  fromName: 'YourStore',
  toPhone: '+380XXXXXXXXX',
  messageType: 'transaction',
  text: 'Hi %name=1%! Order %name=2% shipped. Track: %url=3%',
  variables: [
    { id: 1, type: 'name', value: 'John' },
    { id: 2, type: 'name', value: 'ORD-12345' },
    { id: 3, type: 'url', value: 'https://example.com/track/ORD-12345' }
  ]
});

console.log('Message sent:', result.messageId);

PHP

<?php

class CascadeVariables {
    private $baseUrl = 'https://restapi.smsbat.com';
    private $apiKey;

    public function __construct($apiKey) {
        $this->apiKey = $apiKey;
    }

    public function uploadVariables($variables) {
        $ch = curl_init($this->baseUrl . '/api/items');

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'X-Authorization-Key: ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_POSTFIELDS,
                   json_encode(['variables' => $variables]));

        $response = curl_exec($ch);
        curl_close($ch);

        return json_decode($response, true);
    }

    public function sendWithVariables($id, $fromName, $toPhone,
                                     $messageType, $text, $variables) {
        // Upload variables
        $this->uploadVariables($variables);

        // Send message
        $message = [
            'id' => $id,
            'fromName' => $fromName,
            'toPhone' => $toPhone,
            'messageType' => $messageType,
            'text' => $text
        ];

        $ch = curl_init(
            $this->baseUrl . '/api/CascadeMessage/send_message/async'
        );

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'X-Authorization-Key: ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([$message]));

        $response = curl_exec($ch);
        curl_close($ch);

        $result = json_decode($response, true);
        return $result[0];
    }
}

// Usage
$cascade = new CascadeVariables('your-api-key');

$variables = [
    ['id' => 1, 'type' => 'name', 'value' => 'John'],
    ['id' => 2, 'type' => 'name', 'value' => 'ORD-12345'],
    ['id' => 3, 'type' => 'url', 'value' => 'https://example.com/track/ORD-12345']
];

$result = $cascade->sendWithVariables(
    'order-notification',
    'YourStore',
    '+380XXXXXXXXX',
    'transaction',
    'Hi %name=1%! Order %name=2% shipped. Track: %url=3%',
    $variables
);

echo "Message sent: " . $result['messageId'] . "\n";

အကောင်းဆုံးအလေ့အကျင့်များ

ပြောင်းလဲနိုင်သော ID များ

  • ✅ ဆက်တိုက် ID များ (1၊ 2၊ 3၊ ...)
  • ✅ တူညီသောကိန်းရှင်များပါသော မက်ဆေ့ချ်အမြောက်အမြားအတွက် ID များကို ပြန်သုံးပါ။
  • ✅ Document variable ID mapping
  • ❌ ကျပန်း ID များကို မသုံးပါနှင့်
  • ❌ ID နံပါတ်များကို မကျော်ပါနှင့်

ပြောင်းလဲနိုင်သော တန်ဖိုးများ

  • ✅ မတင်မီ တန်ဖိုးများကို စစ်ဆေးပါ။
  • ✅ အထူးဇာတ်ကောင်များကို စနစ်တကျ ကိုင်တွယ်ပါ။
  • ✅ အစွန်းအိတ်များဖြင့် စမ်းသပ်ပါ။
  • ❌ HTML ကို name variable တွေမှာ မထည့်ပါနဲ့။
  • ❌ သင့်လျော်သော အရှည်ကန့်သတ်ချက်ထက် မကျော်လွန်ပါစေနှင့်

URL ပြောင်းလဲမှုများ

  • ✅ URL ရှည်များအတွက် short_url ကိုသုံးပါ။
  • ✅ ခြေရာခံခြင်းဆိုင်ရာ ကန့်သတ်ချက်များ ပါဝင်ပါသည်။
  • ✅ HTTPS ကိုသုံးပါ။
  • ❌ သံသယဖြစ်ဖွယ်ရှိသော URL များကို မသုံးပါနှင့်
  • ❌ အရေးကြီးသောဒေတာကို URL များတွင် မထည့်ပါနှင့်

စွမ်းဆောင်ရည်

  • variable များကို တစ်ကြိမ် အပ်လုဒ်လုပ်ပါ၊ မက်ဆေ့ခ်ျများစွာ ပို့ပါ။
  • Batch variable အပ်လုဒ်များ
  • အသုံးများသော ကိန်းရှင်များ ကက်ရှ်
  • ကိန်းရှင်ဟောင်းများကို အခါအားလျော်စွာ ရှင်းလင်းပါ။

အဆင့်မြင့်ပုံစံများ

အစုလိုက် စိတ်ကြိုက်ပြုလုပ်ခြင်း။

async function sendBulkPersonalized(recipients) {
  const messages = [];
  const variables = [];
  let varId = 1;

  recipients.forEach((recipient, index) => {
    // Variables for this recipient
    const nameVarId = varId++;
    const orderVarId = varId++;
    const urlVarId = varId++;

    variables.push(
      { id: nameVarId, type: 'name', value: recipient.name },
      { id: orderVarId, type: 'name', value: recipient.orderId },
      { id: urlVarId, type: 'url', value: recipient.trackingUrl }
    );

    messages.push({
      id: `order-${recipient.orderId}`,
      fromName: 'YourStore',
      toPhone: recipient.phone,
      messageType: 'transaction',
      text: `Hi %name=${nameVarId}%! Order %name=${orderVarId}% shipped. Track: %url=${urlVarId}%`
    });
  });

  // Upload all variables
  await uploadVariables(variables);

  // Send all messages
  return await sendBulk(messages);
}

Template စနစ်

class MessageTemplate {
  constructor(template) {
    this.template = template;
    this.varIdCounter = 1;
  }

  create(data) {
    const variables = [];
    let text = this.template;

    // Replace placeholders with variable syntax
    Object.entries(data).forEach(([key, value]) => {
      const varId = this.varIdCounter++;
      variables.push({
        id: varId,
        type: this.getVarType(value),
        value: value
      });

      text = text.replace(`{{${key}}}`, `%${this.getVarType(value)}=${varId}%`);
    });

    return { text, variables };
  }

  getVarType(value) {
    if (value.startsWith('http')) return 'url';
    return 'name';
  }
}

// Usage
const template = new MessageTemplate(
  'Hi {{name}}! Order {{orderId}} shipped. Track: {{trackUrl}}'
);

const { text, variables } = template.create({
  name: 'John',
  orderId: 'ORD-123',
  trackUrl: 'https://example.com/track/ORD-123'
});

await sendWithVariables({ text, variables });

ပြဿနာဖြေရှင်းခြင်း။

ကိန်းရှင်များကို အစားထိုးမထားပါ။

  • မပို့မီ variable များကို အပ်လုဒ်လုပ်ထားကြောင်း အတည်ပြုပါ။
  • စာသားတွင် ပြောင်းလဲနိုင်သော ID ကိုက်ညီမှုများကို စစ်ဆေးပြီး အပ်လုဒ်လုပ်ပါ။
  • မှန်ကန်သော syntax ကိုသေချာစေပါ- %type=id%
  • ပြောင်းလဲနိုင်သောအမျိုးအစားကိုက်ညီမှုတန်ဖိုးကိုအတည်ပြုပါ။

URL အတိုချုံ့ခြင်း မအောင်မြင်ပါ။

  • URL သည် မှန်ကန်ပြီး ဝင်ရောက်နိုင်သည်ကို စစ်ဆေးပါ။
  • URL ကို http:// သို့မဟုတ် https:// ဖြင့် စတင်စစ်ဆေးပါ။
  • URL ကို အတိုချုံးမထားကြောင်း သေချာပါစေ။
  • short_url အစား url ကိုသုံးကြည့်ပါ။

ပြောင်းလဲနိုင်သော ကန့်သတ်ချက် ကျော်လွန်သွားပါပြီ။

  • ပြောင်းလဲနိုင်သောအကန့်အသတ်များအတွက် ပံ့ပိုးကူညီမှုထံ ဆက်သွယ်ပါ။
  • ဖြစ်နိုင်လျှင် ပြောင်းလဲနိုင်သော ID များကို ပြန်သုံးပါ။
  • ပြောင်းလဲမှုဟောင်းများကိုရှင်းလင်းပါ။
  • ပြောင်းလဲနိုင်သောအသုံးပြုမှုကို ပိုမိုကောင်းမွန်အောင်ပြုလုပ်ပါ။

နောက်အဆင့်များ

  • Send Messages - Cascade မက်ဆေ့ချ်များ ပို့ပါ။
  • Message Types - မက်ဆေ့ခ်ျအမျိုးအစားများကို စူးစမ်းပါ။
  • SMSBAT API - SMSBAT API အကြောင်း လေ့လာပါ။