Monday, April 5, 2021

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API.

Transactional SMS usually come with One Time PIN (OTP) to verify the user identity who is using your app. It is considered as one of the common two factor authentication method. The OTP is unique and bind to a specific account and it is generated using hash algorithm. The hash algorithm I would recommend is HMAC based one time password, for more details please refer to this Wiki: https://en.wikipedia.org/wiki/HMAC-based_One-Time_Password. You may also find a lot sample code library available from Google.

Prior in calling the Short Message Service API from your system, you need to create an Access Key first. You need the access key to get authorized to invoke the API method to send SMS.



After creating an Access Key, you can go to the Developer Guide to check out the sample code. I find that Alibaba Cloud have done a very good job in online documentation and even provide a real time interpreter to test the source code on the fly which actually help improving the learning curve of the developer. It allow the developer perform code modification directly from the browser and test the code and monitor the difference.


The highlighted yellow text below from the sample source code is the place where you need to modify base on the Access Key that you had generated earlier. The aqua text below is where you put your HMAC One Time Password.

using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace CommonRequestDemo
{
class Program
{
static void Main(string[] args)
{
IClientProfile profile = DefaultProfile.GetProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.Method = MethodType.POST;
request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com";
request.Version = "2018-05-01";
request.Action = "SendMessageToGlobe";
// request.Protocol = ProtocolType.HTTP;
request.AddQueryParameters("To", "601612312312");
request.AddQueryParameters("Message", "Your OTP is 123456 from Alibaba Cloud");

try {
CommonResponse response = client.GetCommonResponse(request);
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
catch (ServerException e)
{
Console.WriteLine(e);
}
catch (ClientException e)
{
Console.WriteLine(e);
}
}
}
}

The following link contain all the possible error codes which is useful for you to troubleshoot any issue when you attempt to send SMS.

How to Send SMS with Alibaba Cloud Short Message Service?

SMS is a very commonly used tool to send notification, promotion or transaction verification. I would say majority of the software todays require sending SMS service. Hence, Alibaba Cloud also provide the service for their clients.


In Alibaba Cloud Short Message Service, you can purchase SMS package base on the country mobile that you intend to send, otherwise you can opt for the Global package which is much more expensive but support world wide any mobile number.

The SMS package price is different for different country, potentially due to the telco operator in different country charge the SMS service differently.


After purchasing the SMS package, if you wish to test the SMS service from Alibaba Cloud, you can use the Quick Start function to test sending SMS to your own mobile number to confirm receiving the message.

Next, go to the Go Globe if you are not from China and intend to broadcast promotional SMS to your customers.


Create a New Campaign, then enter the Campaign Name then follow by the promotional message that you wish to send. If you want the SMS content to have variable value, you need to download the sample Excel file from the "example download".

Enter the variable name with $ sign with curly bracket such as ${name}. The variable value will be changed and different base on the Excel file content. The variable name is the first row of the Excel. The To column must be remained as it is, add more column if you wish to have more variables to be supported.

Then, click the Import Number button to upload the Excel file that you have the variable setup.

If you wish to broadcast your SMS at a scheduled time, just hit the Schedule Campaign button and simply choose the date and time you wish.

Lastly, hit the Schedule Campaign button and you are good and just wait for SMS broadcast automatically until the scheduled time.

It is advisable that before scheduling the campaign or perform immediate broadcast, always test the broadcast with a few of your own or friends mobile first to verify the content. SMS broadcast cannot be retracted if there is any mistake that you discover later.

You can check your SMS broadcast report under the Statistic section. So that, you can see which mobile number is failed to be delivered the SMS.


 

Tuesday, September 15, 2020

How to Resize Partition without Losing Data in Ubuntu?

Today I encounter an issue relates to the disk storage with my server in Alibaba Cloud. I am hosting blockchain node on the server, and the storage utilization grow over time. Therefore, I write this blog is to share with you how to resize a disk online with Alibaba Cloud, then resize the partition without losing data.

First of all, login to your Alibaba Cloud console or any other cloud provider, select the data disk that you want to resize.

Key in the storage size that you want to increase, then make sure to select Online Resizing option.

After resizing the disk, you need to increase the existing partition, otherwise, the new storage size is still not usable.

Login to your Ubuntu server, then use the df command to check your existing disk space:

I have only one data disk in my server. Hence, my data disk is /dev/vdb, I suppose yours should be the same. You also can refer to my other post on how to mount data disk to your server.

Now, in order to resize the partition, we need to remove the existing one and then create a new one with the new size. Not to worry about the "remove" keyword, it will not remove your file. It mean delete the partition information only.

Run the fdisk command:

fdisk /dev/vdb

d = delete the selected partition
n = create new partition
p = primary partition

In order to maximize the partition, just simply press Enter to select the default partition, first sector and last sector. 

WARNING: You will be prompted Partition #1 contains a ext4 signature.
This is the most important step, make sure you key in NO to maintain the signature file, otherwise you will lose all your data.

The signature partition is to inform you that there is something in the partition, this warning only happen when it is not empty.

Once you are done, enter wq command to write the change.

If you run the ls command, you will notice your data is still around. Now, resize the partition by running the following command:

resize2fs /dev/vdb1

Now your data disk partition new available storage has been increased effectively. You can verify it by executing the df command.

Cheers!

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...