Send Sms/Otp in nim - Mersal

Send Sms/Otp in nim - Mersal

a wrapper for TextBelt

Table of contents

Two days ago, someone asked me about an api to send sms/otp for python, and well I know about as the best api service around I am aware of, even their api is so easy but I thought to make a package for nim to ease the api for nim user and another way of learning nim.

So what does it provide:

  • Send sms to any international mobile number using the standard number way +CCMobile
  • Track the delivery of any sms sent
  • Send Otp to any mobile number same like sending message
  • Make your own message content instead of default Your verification code is $OTP
  • verify the otp
  • check your credit balance

Is it free ?

Texetbelt provide you with free key textbelt to be able to send one free message a day, but you can purchase an sms package from here - , you will need to use a key with credit.

Install mersal

To install mersal for your nim development package:

nimble install mersal

then import mersal and enjoy using it is api in your app.


Bellow an example of a full app to send a message:

import termui, terminal
import mersal

const logo = """

   _   __ ___  ___    ___   _   __
  / \,' // _/ / o | ,' _/ .' \ / /
 / \,' // _/ /  ,' _\ `. / o // /_
/_/ /_//___//_/`_\/___,'/_n_//___/
                 Built by FOXOMAN
                            v 1.0

const help = """
[*] Use E.164 mobile numbers format:

    Example: +447712345678:

    Prefix      Country code      Subscriber number
    +           44 (UK)           7712345678

styledEcho(fgCyan, logo, resetStyle)
styledEcho(fgYellow, help, resetStyle)
styledEcho(fgRed, """[*] Use at your own risk!
[*] 'textbelt' is free key for one message a day only.
""", resetStyle)

let mobile = termuiAsk("What is the mobile you want to send the message to?",
    defaultValue = "+447712345678")
let message = termuiAsk("What is your message?",
    defaultValue = "Hello World")
let key = termuiAsk("What is your API Key?",
    defaultValue = "textbelt")

let sendingMsg = termuiSpinner("Prepare to send the message...")

sendingMsg.update("Sending the message...")

let (ok, id, credit, error) = sendSms(mobile, message, key)

sendingMsg.update("Getting the resposnse....")

if not ok: & "\n")

  sendingMsg.complete("TextId: " & id &
      " | quotaRemaining: " & $credit & "\n")

discard getch()