Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reqwest = { version = "0.10.4", features = ["blocking", "stream", "json"] }
tokio = { version = "0.2", features = ["full"] }
serde = { version = "1.0.110", features = ["derive"] }
serde_json = "1.0.53"
urlencoding = "1"
futures = "0.3"
anyhow = "1.0.31"
tokio-util = "0.3.1"
Expand Down
12 changes: 12 additions & 0 deletions examples/keyboard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "keyboard"
version = "0.1.0"
authors = ["PatriotRossii <patriotrossii2019@mail.ru>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "0.2", features = ["full"] }
vkapi = { path = "../../" }
rand = "0"
40 changes: 40 additions & 0 deletions examples/keyboard/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use vkapi::{
VK, param,
types::keyboard::{Keyboard, Button, ButtonColor, TextButton, VKPayButton, LocationButton}
};
use rand::Rng;

#[tokio::main]
async fn main() {
let access_token = std::env::var("ACCESS_TOKEN").expect("Failed to get ACCESS_TOKEN environment variable");
let peer_id = std::env::var("PEER_ID").expect("Failed to get PEER_ID environment variable");

let buttons = vec![
vec![
Button::new(LocationButton::new(""), None).unwrap(),
],
vec![
Button::new(VKPayButton::new("", "action=transfer-to-group&group_id=1&aid=10"), None).unwrap(),
],
vec![
Button::new(TextButton::new("Negative", ""), Some(ButtonColor::Negative)).unwrap(),
Button::new(TextButton::new("Positive", ""), Some(ButtonColor::Positive)).unwrap(),
Button::new(TextButton::new("Primary", ""), Some(ButtonColor::Primary)).unwrap(),
]
];
let keyboard = Keyboard::new(buttons, true, None).expect("Failed to build a keyboard");
println!("{}", keyboard.to_string());

let mut rng = rand::thread_rng();
let random_id: i64 = rng.gen_range(0, 50_000_000);
let mut params = param! {"peer_id" => &peer_id, "message" => "Сообщение", "keyboard" => &keyboard.to_string(), "random_id" => &format!("{}", random_id)};

let mut vk_api = vkapi::VK::new("5.130".to_string(), "en".to_string());
vk_api.set_access_token(access_token);

let response = vk_api
.request::<serde_json::value::Value>("messages.send", &mut params)
.await
.unwrap();
println!("{}", response);
}
35 changes: 17 additions & 18 deletions src/types/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,24 @@ impl Destination {
}
}

/// __TODO__: Replace `String` to `&str`
pub fn pick_param(&self) -> String {
pub fn pick_param(&self) -> &'static str {
match self {
Album => "file1".to_owned(),
Wall => "photo".to_owned(),
OwnerPhoto => "photo".to_owned(),
Message => "photo".to_owned(),
ChatPhoto => "file".to_owned(),
MarketPhoto => "file".to_owned(),
MarketAlbum => "file".to_owned(),
Audio => "file".to_owned(),
Video => "video_file".to_owned(),
Document => "file".to_owned(),
DocumentWall => "file".to_owned(),
DocumentMessage => "file".to_owned(),
Cover => "photo".to_owned(),
AudioMessage => "file".to_owned(),
StoryPhoto => "file".to_owned(),
StoryVideo => "video_file".to_owned(),
Album => "file1",
Wall => "photo",
OwnerPhoto => "photo",
Message => "photo",
ChatPhoto => "file",
MarketPhoto => "file",
MarketAlbum => "file",
Audio => "file",
Video => "video_file",
Document => "file",
DocumentWall => "file",
DocumentMessage => "file",
Cover => "photo",
AudioMessage => "file",
StoryPhoto => "file",
StoryVideo => "video_file",
}
}
}
Loading