33import cc .blynk .server .core .model .DashBoard ;
44import cc .blynk .server .core .model .DataStream ;
55import cc .blynk .server .core .model .auth .Session ;
6+ import cc .blynk .server .core .model .auth .User ;
67import cc .blynk .server .core .model .enums .PinType ;
78import cc .blynk .server .core .model .widgets .others .webhook .Header ;
89import cc .blynk .server .core .model .widgets .others .webhook .WebHook ;
2425
2526import static cc .blynk .server .core .protocol .enums .Command .WEB_HOOKS ;
2627import static cc .blynk .utils .StringUtils .DATETIME_PATTERN ;
28+ import static cc .blynk .utils .StringUtils .DEVICE_OWNER_EMAIL ;
2729import static cc .blynk .utils .StringUtils .GENERIC_PLACEHOLDER ;
2830import static cc .blynk .utils .StringUtils .PIN_PATTERN ;
2931import static cc .blynk .utils .StringUtils .PIN_PATTERN_0 ;
@@ -68,7 +70,7 @@ public WebhookProcessor(DefaultAsyncHttpClient httpclient,
6870 this .webhookFailureLimit = failureLimit ;
6971 }
7072
71- public void process (Session session , DashBoard dash , int deviceId , short pin ,
73+ public void process (User user , Session session , DashBoard dash , int deviceId , short pin ,
7274 PinType pinType , String triggerValue , long now ) {
7375 WebHook webhook = dash .findWebhookByPin (deviceId , pin , pinType );
7476 if (webhook == null ) {
@@ -78,12 +80,12 @@ public void process(Session session, DashBoard dash, int deviceId, short pin,
7880 checkIfNotificationQuotaLimitIsNotReached (now );
7981
8082 if (webhook .isNotFailed (webhookFailureLimit ) && webhook .url != null ) {
81- process (session , dash .id , deviceId , webhook , triggerValue );
83+ process (user , session , dash .id , deviceId , webhook , triggerValue );
8284 }
8385 }
8486
85- private void process (Session session , int dashId , int deviceId , WebHook webHook , String triggerValue ) {
86- String newUrl = format (webHook .url , triggerValue );
87+ private void process (User user , Session session , int dashId , int deviceId , WebHook webHook , String triggerValue ) {
88+ String newUrl = format (webHook .url , triggerValue , user . email );
8789
8890 if (!WebHook .isValidUrl (newUrl )) {
8991 return ;
@@ -114,7 +116,7 @@ private void process(Session session, int dashId, int deviceId, WebHook webHook
114116 builder .setHeader (header .name , header .value );
115117 if (webHook .body != null && !webHook .body .isEmpty ()) {
116118 if (CONTENT_TYPE .equals (header .name )) {
117- String newBody = format (webHook .body , triggerValue );
119+ String newBody = format (webHook .body , triggerValue , user . email );
118120 log .trace ("Webhook formatted body : {}" , newBody );
119121 builder .setBody (newBody );
120122 }
@@ -123,7 +125,7 @@ private void process(Session session, int dashId, int deviceId, WebHook webHook
123125 }
124126 }
125127
126- log .trace ("Sending webhook. " , webHook );
128+ log .trace ("Sending webhook. {} " , webHook );
127129 builder .execute (new AsyncCompletionHandler <Response >() {
128130
129131 private int length = 0 ;
@@ -184,7 +186,7 @@ private static boolean isValidResponseCode(int responseCode) {
184186 }
185187 }
186188
187- private static String format (String data , String triggerValue ) {
189+ private static String format (String data , String triggerValue , String ownerEmail ) {
188190 //this is an ugly hack to make it work with Blynk HTTP API.
189191 String quotedValue = Matcher .quoteReplacement (triggerValue );
190192 data = PIN_PATTERN .matcher (data ).replaceFirst (quotedValue );
@@ -214,6 +216,7 @@ private static String format(String data, String triggerValue) {
214216 default :
215217 data = GENERIC_PLACEHOLDER .matcher (data ).replaceFirst (quotedValue );
216218 data = DATETIME_PATTERN .matcher (data ).replaceFirst (Instant .now ().toString ());
219+ data = DEVICE_OWNER_EMAIL .matcher (data ).replaceFirst (ownerEmail );
217220 }
218221 return data ;
219222 }
0 commit comments