Skip to content

ClickSend/integration-sqs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClickSend AWS SQS Integration

Sending SMS through Amazon SQS over ClickSend v3 API:

This tutorial shows you how to integrate the AWS SQS service with ClickSend API using AWS Lambda. For troubleshooting purposes please contact our support team.

There are three main components used when sending an SMS using the ClickSend API.

  1. The event producer which will create and send the events to AWS SQS.

  2. AWS SQS which will deliver the events produced by the producer to the Lambda event listener.

  3. AWS Lambda which will be triggered by SQS events and send SMS over ClickSend API.

Prerequisites:

To get started you will need:

After you have fulfilled the above prerequisites, follow these steps to install the dependencies and run the program:

Setting up your computer

  1. Open your command line / shell

    window_cmd terminal

  2. Install GitHub-CLI using your terminal or cmd.

  3. Clone the GitHub repo by following this SQS-repo link or download the zip file.

    Github Clone

AWS Dependencies and configuration

  1. Browse to the producer nodejs folder from your command line / shell.

  2. Install project dependencies.

    npm install

    For example, on Window’s cmd:

    AWS SDK UUID

AWS credentials and required permissions

  1. There are two ways to obtain the credentials and permissions depending on whether you are working under an organisation or are the AWS administrator.

    Option 1: If you are working under an organisation

    Ask your AWS administrator for your credentials:

    Group

    Your AWS administrator will also need to grant you the permissions attached in the policy.json file under the nodejs folder, by creating a new policy.

    JSON

    Option 2: You are the administrator

    If you are the administrator or you have created a new AWS account, copy your credentials from the security credentials:

    Group
  2. Configure your AWS CLI by setting up the .AWS folder directory and creating credential (obtained from above) and config (your region) files under this directory. Make sure these files do not have any extensions. Follow these links for more instructions:

    a. cli-config-files
    b. config-file-location
    For example:

    CLI Credentials

Creating an AWS-SQS queue

  1. To setup your AWS-SQS, go to your AWS console and search for “SQS” and select the first option:

    AWS SQS
  2. Click on “Create queue”:

    Create queue
  3. Select a name for the queue that’s relevant to you. There's no need to change any settings/configuration/access policies; the default settings are enough.

    Queue name
  4. After selecting the name, press the create queue button.

    Queue Name
  5. After creating the queue, a window with the following message should appear on your screen. Copy the queue URL.

    Queue

Sending SMS to an AWS SQS Queue:

  1. This guide shows two ways send SMS to AWS SQS queue; using Java or NodeJS.

    Option 1: Using Java

    Open the producer java folder as a Maven project from any IDE. For example, on visual studio code: JAVA

    a. If you do not have Maven installed on your IDE, you should first install it from your IDE’s extension page. For example, on visual studio code:

    Maven

    b. Or download and install from: Apache-Maven

    Replace the AWS SQS queue URL in the main.java file with the created queue URL:

    Queue URL

    Insert your region and change the from, to, and message content. Check the comments in the file for more details:

    Region

    Run the program. You should see a message response like this in your IDE’s terminal:

    Success

    Option 2: Using NodeJS

    Open the producer nodejs folder from any IDE.

    NodeJS

    Replace the AWS SQS queue URL in the main.js file with the created queue URL, For example, on visual studio code:

    Replacing URL
  2. Change the from, to, and message content. Check the comments in the file for more details:

    Message
  3. Execute the "main.js" file by running the following command on command line / shell:

    node main.js

    You should see a success message like this in IDE's terminal:

    Success

To test whether the message is in the queue

  1. To check whether this message has reached the queue, click the “Send and receive messages” button.

    SMS queue
  2. Then click “Poll for messages”, there should be messages available.

    Poll

Creating a Lambda event listener:

Now we need to create an AWS Lambda function which will accept and send the messages to the ClickSend API.

  1. In the search bar of your AWS console enter and select Lambda.

    Lambda
  2. Click create function

    Function
  3. Enter a function name

    Function Name
  4. In the permission section search and add “Amazon SQS poller permissions” under the “Policy templates” field. Click on “Create function”.

    Policy

Setting up the Lambda function with our consumer

Now that our Lambda function is created, we need to add code this function that enables it to send the messages via the ClickSend API.

  1. Browse to the consumer/Lambda folder on your computer from terminal/cmd.

    Lambda Folder
  2. Install ClickSend dependencies by running these commands:

    • Install ClickSend SDK for sending messages from the command line / shell

      npm i clicksend
    • Install TypeScript which will be used to compile the code:

      sudo npm install typescript
    • For compiling typescript into javascript:

      sudo npm add request http bluebird @types/node
      tsc --target es5 /node_modules/clicksend/api.ts
    • For more information, please follow the setup guide in GitHub.

  3. After the installation, you should have these files/folders in your consumer folder.

    File Check
  4. Compress these 3 files/folder into a zip file, choose any name.

  5. Replace the “sqssmsconsumer” with the Lambda function's name and “Lambda.zip” with your zip file name. Run the command from your command line / shell:

    aws lambda update-function-code --function-name sqssmsconsumer --zip-file fileb://Lambda.zip
  6. Refresh the page, you should see notification stating:

    Notification

Setting up your ClickSend credentials on AWS Lambda function

  1. Get your ClickSend credential, follow this link: ClickSend Credentials

  2. Set your ClickSend credentials on AWS Lambda, we need to create two environment variables on your Lambda function. Go to the configuration tab and click on "Environment variables". Then click on "Edit".

    ENV Variables
  3. Click on "Add environment variable":

    Add Variables
  4. Create the two environment variables named “username” and “api_key” and insert your ClickSend credentials in the value column and click save.

    Two Variables
  5. You should be able to see the created environment variable.

    Added Variables

Creating trigger for the Lambda function

  1. Click on the "Add trigger":

    Add Trigger
  2. Search and select "SQS" from search bar

    Search SQS
  3. Search and select your created queue from the SQS queue search bar.

    Created queue
  4. Click on the “Add” button. You should the following message:

    Added trigger

Done. Now everything is set up and configured.

Now whenever you want to send a message to someone, just change the parameters in the one of producers and run.

You can also see logs of your sent messages on the CloudWatch logs tab. If the log of messages does not appear here, click the “View logs in CloudWatch” button.

Logs

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6