Module switch

Source
Expand description

Send messages, bulk messages, fetch/request sender ids, CRUD phonebooks.

§Examples

§Fetch Phonebooks.

use termii_rust::{async_impl::rest::termii, common::switch::campaign::PhoneBookItem};

let client = termii::Termii::new("Your API key");

let phonebooks: Vec<PhoneBookItem> = client.switch.campaign.get(Some(1)).await.unwrap();

println!("{:?}", phonebooks);

§The above code is limited by termii’s pagination. You can get all your phonebooks with the all function like such

let phonebooks: Vec<PhoneBookItem> = client.switch.campaign.all().await.unwrap();

§Send a message to a recipient.

use termii_rust::{
    async_impl::rest::termii,
    common::switch::messaging::{Channel, MessageRequest, MessageType},
};

let client = termii::Termii::new("Your API key");

let message_payload = MessageRequest::new(
    "234XXXXXXXXXX".to_string(),
    "Your org sender id".to_string(),
    "Your message".to_string(),
    MessageType::Plain,
    Channel::Generic,
);

let message_response = client.switch.messaging.send(message_payload).await.unwrap();

println!("{:?}", message_response);

§Send a message to a recipient using termii’s auto generated number.

use termii_rust::{async_impl::rest::termii, common::switch::number::NumberMessageRequest};

let client = termii::Termii::new("Your API key");

let message_payload =
    NumberMessageRequest::new("234XXXXXXXXXX".to_string(), "Your message".to_string());

let message_response = client.switch.number.send(message_payload).await.unwrap();

println!("{:?}", message_response);

§Fetch your organization’s sender ID’s.

use termii_rust::async_impl::rest::termii;

let client = termii::Termii::new("Your API key");

let sender_id = client.switch.sender_id.get(Some("1")).await.unwrap();

println!("{:?}", sender_id);

§The above code is limited by termii’s pagination. You can get all your sender ID’s with the all function like such

let sender_ids = client.switch.sender_id.all().await.unwrap();

§Set a template for your org’s one time pin.

use termii_rust::{
    async_impl::rest::termii,
    common::switch::templates::{TemplatesData, TemplatesRequest},
};

let client = termii::Termii::new("Your API key");

let templates_data =
    TemplatesData::new("Termii", "325821".to_string(), "10 minutes".to_string());

let templates_payload = TemplatesRequest::new(
    "+234XXXXXXXXXX".to_string(),
    "talert".to_string(),
    "1493-csdn3-ns34w-sd3434-dfdf".to_string(),
    templates_data,
);

let templates_response = client
    .switch
    .templates
    .send(templates_payload)
    .await
    .unwrap();

println!("{:?}", templates_response);

Re-exports§

pub use switch::*;
pub use templates::*;
pub use sender_id::*;
pub use campaign::*;
pub use number::*;
pub use messaging::*;

Modules§

campaign
Send and manage campaigns sent to your organization’s phonebook.
messaging
Send messages to customers across termii channels.
number
Send messages to your organization’s customers using auto-generated messaging numbers.
sender_id
Request new Sender Id and retrieve their status.
switch
templates
Request and Send template messageds across different messaging channels.