Using messagebird-async to send sms text messages

Hi, I'm trying to send a phone text message through Rust to validate peoples' phone numbers to register their accounts on a web app I'm building. I've copied and pasted the code seen on the crate's site and properly added in the additional dependencies but it still shows an error at "let fut = fut.and_then" saying that there's no method named "and_then" found for the struct. Could someone provide a fix for this and also if possible give a short explanation on how to use this to send sms messages? I'm assuming you swap out SMS_RECIPIENT with the actual phone number, but that's about it. Do you need an access code or does the copied code already include it?

This is the code from the messagebird-async crate:

#[macro_use]
extern crate log;
extern crate env_logger;
extern crate futures;
extern crate messagebird_async;
extern crate tokio_core;

use futures::future::Future;
use messagebird_async::errors::*;
use messagebird_async::sms;
use messagebird_async::sms::*;

fn main() -> Result<(), MessageBirdError> {
    env_logger::init();

    let msisdn_str = std::env::var("SMS_RECIPIENT".to_string())
        .expect("SMS_RECIPIENT should contain the number without prefix");
    let msisdn: Msisdn = Msisdn::from_str(msisdn_str.as_str())
        .expect("SMS_RECIPIENT did not contain a valid number");

    info!("example: sending a message");
    let sendable = sms::send::SendParameters::builder()
        .payload(
            PayloadType::Sms,
            Payload::Text("fun".to_string()),
            PayloadEncoding::Auto,
        )
        .origin(AlphaNumeric("inbox".to_string()).into())
        .add_recipient(msisdn.into())
        //.add_recipient(Recipient::new())
        .build();

    let accesskey = AccessKey::from_env()?;
    let fut = RequestSend::new(&sendable, &accesskey);
    let fut = fut.and_then(|sent_msg: Message| {
        info!("{:?}", sent_msg);
        futures::future::ok(())
    });
    let mut core = tokio_core::reactor::Core::new().unwrap();
    core.run(fut.map(|_| ()))
}

So I replaced my futures in dependencies to a previous version (0.1) and that seemed to do the trick. I'm still running into issues using this crate though, I tried replacing SMS_RECIPIENT with a phone number I have and it doesn't seem to work no matter how I format it. Would appreciate it if someone who knows how to use this crate could type an example of what to replace SMS_RECIPIENT with!

I don't know the library in question, but be aware that you are using very old an deprecated libraries. I would probably go for using modern reqwest with some web api that offers sending sms by an API.

Thanks for the suggestion, Alice.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.