1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! This module provides a `MediaModel` struct that represents a media message in a Messenger conversation.
//!
//! ## MediaModel Struct
//!
//! The `MediaModel` struct represents a media message in a Messenger conversation. This message can be an image or a video.
//!
//! ### Fields
//!
//! * `messaging_type: String` - The type of messaging. For media messages, this is always "RESPONSE".
//! * `recipient: Recipient` - The recipient of the media message.
//! * `message: Attachment` - The attachment that contains the type of the media file and the Facebook URL of the media file.
//!
//! ### Methods
//!
//! * `new(sender: &'m str, media_type: &'m str, url: &'m str) -> Self` - Creates a new `MediaModel` instance.
//!
//! ## Examples
//!
//! Sending a video from static dir:
//!
//! ```rust
//! use russenger::prelude::*;
//!
//! async fn send_file_from_static_dir(res: Res, req: Req) -> Result<()> {
//! let text = TextModel::new(&req.user, "Sending file... Please wait!");
//! res.send(text).await?;
//! let url = format!("{host}/static/video.mp4", host = req.host);
//! res.send(MediaModel::new(&req.user, "video", &url)).await?;
//!
//! Ok(())
//! }
//! ```
//!
//! Sending a media file:
//!
//! ```rust
//! use russenger::response_models::media::MediaModel;
//! let message = MediaModel::new("sender_id", "image", "https://cdn.pixabay.com/photo/2017/06/28/10/53/board-2450236_960_720.jpg");
//! ```
//!
//! ## Returns
//!
//! A POST request to the Facebook API to send a media file using the Facebook URL.
//!
//! ## Reference
//!
//! [Facebook Messenger Platform - Send API Reference](https://developers.facebook.com/docs/messenger-platform/reference/send-api)
use Serialize;
use Recipient;
use ResponseModel;
/// `MediaModel` is used to send media files such as images and videos to the recipient via a Facebook URL.
///
/// The `MediaModel` struct contains the following fields:
/// - `messaging_type`: A string that specifies the type of messaging. For media messages, this is always "RESPONSE".
/// - `recipient`: A `Recipient` struct that specifies the recipient of the media file.
/// - `message`: An `Attachment` struct that contains the type of the media file and the Facebook URL of the media file.
///
/// This model does not allow any external URLs, only those on Facebook.
///
/// # Methods
///
/// * `new(sender: &'m str, media_type: &'m str, url: &'m str) -> Self` - Creates a new `MediaModel` instance.
///
/// # Examples
///
/// Sending a video from static dir
/// ```rust
/// use russenger::prelude::*;
///
/// async fn send_file_from_static_dir(res: Res, req: Req) -> Result<()> {
/// let text = TextModel::new(&req.user, "Sending file... Please wait!");
/// res.send(text).await?;
/// let url = format!("{host}/static/video.mp4", host = req.host);
/// res.send(MediaModel::new(&req.user, "video", &url)).await?;
///
/// Ok(())
/// }
/// ```
///
/// Sending a media file:
///
/// ```rust
/// use russenger::response_models::media::MediaModel;
/// let message = MediaModel::new("sender_id", "image", "https://cdn.pixabay.com/photo/2017/06/28/10/53/board-2450236_960_720.jpg");
/// ```
///
/// [Facebook Documentation](https://developers.facebook.com/docs/messenger-platform/send-messages/template/media)