File tree Expand file tree Collapse file tree 5 files changed +19
-16
lines changed Expand file tree Collapse file tree 5 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ native-tls-vendored = ["reqwest/native-tls-vendored"]
2525realtime = [" dep:tokio-tungstenite" ]
2626# Bring your own types
2727byot = []
28+ webhook = [" dep:hmac" , " dep:sha2" , " dep:hex" ]
2829
2930[dependencies ]
3031async-openai-macros = { path = " ../async-openai-macros" , version = " 0.1.0" }
@@ -50,9 +51,9 @@ secrecy = { version = "0.10.3", features = ["serde"] }
5051bytes = " 1.9.0"
5152eventsource-stream = " 0.2.3"
5253tokio-tungstenite = { version = " 0.26.1" , optional = true , default-features = false }
53- hmac = " 0.12.1 "
54- sha2 = " 0.10.8 "
55- hex = " 0.4.3 "
54+ hmac = { version = " 0.12" , optional = true , default-features = false }
55+ sha2 = { version = " 0.10" , optional = true , default-features = false }
56+ hex = { version = " 0.4" , optional = true , default-features = false }
5657
5758[dev-dependencies ]
5859tokio-test = " 0.4.4"
Original file line number Diff line number Diff line change @@ -28,17 +28,6 @@ pub enum OpenAIError {
2828 InvalidArgument ( String ) ,
2929}
3030
31- /// Errors that can occur when processing webhooks
32- #[ derive( Debug , thiserror:: Error ) ]
33- pub enum WebhookError {
34- /// Invalid webhook signature or signature verification failed
35- #[ error( "invalid webhook signature: {0}" ) ]
36- InvalidSignature ( String ) ,
37- /// Failed to deserialize webhook payload
38- #[ error( "failed to deserialize webhook payload: error:{0} content:{1}" ) ]
39- Deserialization ( serde_json:: Error , String ) ,
40- }
41-
4231#[ derive( Debug , thiserror:: Error ) ]
4332pub enum StreamError {
4433 /// Underlying error from reqwest_eventsource library when reading the stream
Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ mod vector_store_file_batches;
179179mod vector_store_files;
180180mod vector_stores;
181181mod video;
182+ #[ cfg( feature = "webhook" ) ]
182183pub mod webhooks;
183184
184185pub use assistants:: Assistants ;
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ mod upload;
3434mod users;
3535mod vector_store;
3636mod video;
37+ #[ cfg_attr( docsrs, doc( cfg( feature = "webhook" ) ) ) ]
38+ #[ cfg( feature = "webhook" ) ]
3739pub mod webhooks;
3840
3941pub use assistant:: * ;
Original file line number Diff line number Diff line change 1- use crate :: error:: WebhookError ;
21use crate :: types:: webhooks:: WebhookEvent ;
32use base64:: { engine:: general_purpose:: STANDARD as BASE64 , Engine } ;
43use hmac:: { Hmac , Mac } ;
54use sha2:: Sha256 ;
65use std:: time:: { SystemTime , UNIX_EPOCH } ;
76
7+ /// Errors that can occur when processing webhooks
8+ #[ derive( Debug , thiserror:: Error ) ]
9+ pub enum WebhookError {
10+ /// Invalid webhook signature or signature verification failed
11+ #[ error( "invalid webhook signature: {0}" ) ]
12+ InvalidSignature ( String ) ,
13+ /// Failed to deserialize webhook payload
14+ #[ error( "failed to deserialize webhook payload: error:{0} content:{1}" ) ]
15+ Deserialization ( serde_json:: Error , String ) ,
16+ }
17+
818type HmacSha256 = Hmac < Sha256 > ;
919
1020const DEFAULT_TOLERANCE_SECONDS : i64 = 300 ;
@@ -356,7 +366,7 @@ mod tests {
356366 assert ! ( result. is_err( ) ) ;
357367 assert ! ( matches!(
358368 result. unwrap_err( ) ,
359- WebhookError :: Deserialization ( _ )
369+ WebhookError :: Deserialization ( .. )
360370 ) ) ;
361371 }
362372}
You can’t perform that action at this time.
0 commit comments