LoginSignup
7

More than 5 years have passed since last update.

RustでFacebook Messenger Bot 作成

Last updated at Posted at 2016-09-29

rmessenger

Rust用FacebookMessengerのWrapperです.

インストール

Cargo.tomlに以下を追記

rmessenger = "0.0.4"

使いかた

GitHubのREADMEのとおりですが、

テキストメッセージ

extern crate rmessenger;
use rmessenger::bot;

fn main() {
    let bot = bot::Bot::new("<YOUR ACCESS TOKEN>", "<YOUR APP SECRET>");
    bot.send_text_message("<recipient_id>", "hello!");
}

ふつうのテキストメッセージの他にGeneric Templateの形式でも送信できます.

extern crate rmessenger;
use rmessenger::bot;

fn main() {
    let bot = bot::Bot::new("<YOUR ACCESS TOKEN>", "<YOUR APP SECRET>");
    bot.send_generic_message("<recipient_id>>",
                             "[{'title': 'example',
                                'image_url': 'https://petersfancybrownhats.com/company_image.png'
                                }]");
}

crates.ioはこちら

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7