├── basic_auth.ws ├── checksum.ws ├── convert_katakana.ws ├── csv_upload.ws ├── csv_upload_with_form_fields.ws ├── date_compare.ws ├── date_response.ws ├── expiry.ws ├── hello_world.ws ├── multipart_file_upload.ws ├── multipart_form.ws ├── rate_limit.ws ├── return_latest_post_on_get.ws ├── twilio.ws └── upload_files_from_json_to_dropbox.ws /basic_auth.ws: -------------------------------------------------------------------------------- 1 | username = 'john' 2 | password = '1234' 3 | 4 | if (var('request.header.php-auth-user', '') != username and var('request.header.php-auth-pw', '') != password) { 5 | respond('', 401, ['WWW-Authenticate: Basic realm="Authentication required"']); 6 | } 7 | 8 | respond('Login OK!'); 9 | -------------------------------------------------------------------------------- /checksum.ws: -------------------------------------------------------------------------------- 1 | // Simple validation that a public string is genuine 2 | // Example URL: https://webhook.site/token?date=2021-01-01&check=82ba425d0244e0d44ee9db16b52ba376... 3 | 4 | date = var('request.query.date') 5 | check = var('request.query.check') 6 | secret = 'mysecret' 7 | 8 | 9 | if (hash(date + secret, 'sha256') == check) { 10 | respond('Valid') 11 | } 12 | 13 | respond('Not found', 404) 14 | -------------------------------------------------------------------------------- /convert_katakana.ws: -------------------------------------------------------------------------------- 1 | map = [ 2 | "ア" :"A", 3 | "イ" :"I", 4 | "ウ" :"U", 5 | "エ" :"E", 6 | "オ" :"O", 7 | "カ" :"KA", 8 | "キ" :"KI", 9 | "ク" :"KU", 10 | "ケ" :"KE", 11 | "コ" :"KO", 12 | "サ" :"SA", 13 | "シ" :"SHI", 14 | "ス" :"SU", 15 | "セ" :"SE", 16 | "ソ" :"SO", 17 | "タ" :"TA", 18 | "チ" :"CHI", 19 | "ツ" :"TSU", 20 | "テ" :"TE", 21 | "ト" :"TO", 22 | "ナ" :"NA", 23 | "ニ" :"NI", 24 | "ヌ" :"NU", 25 | "ネ" :"NE", 26 | "ノ" :"NO", 27 | "ハ" :"HA", 28 | "ヒ" :"HI", 29 | "フ" :"FU", 30 | "ヘ" :"HE", 31 | "ホ" :"HO", 32 | "マ" :"MA", 33 | "ミ" :"MI", 34 | "ム" :"MU", 35 | "メ" :"ME", 36 | "モ" :"MO", 37 | "ヤ" :"YA", 38 | "ユ" :"YU", 39 | "ヨ" :"YO", 40 | "ラ" :"RA", 41 | "リ" :"RI", 42 | "ル" :"RU", 43 | "レ" :"RE", 44 | "ロ" :"RO", 45 | "ワ" :"WA", 46 | "ヰ" :"I", 47 | "ヱ" :"E", 48 | "ヲ" :"O", 49 | "ン" :"N", 50 | "ヴ" :"V", 51 | "ガ" :"GA", 52 | "ギ" :"GI", 53 | "グ" :"GU", 54 | "ゲ" :"GE", 55 | "ゴ" :"GO", 56 | "ザ" :"ZA", 57 | "ジ" :"JI", 58 | "ズ" :"ZU", 59 | "ゼ" :"ZE", 60 | "ゾ" :"ZO", 61 | "ダ" :"DA", 62 | "ヂ" :"JI", 63 | "ヅ" :"ZU", 64 | "デ" :"DE", 65 | "ド" :"DO", 66 | "バ" :"BA", 67 | "ビ" :"BI", 68 | "ブ" :"BU", 69 | "ベ" :"BE", 70 | "ボ" :"BO", 71 | "パ" :"PA", 72 | "ピ" :"PI", 73 | "プ" :"PU", 74 | "ペ" :"PE", 75 | "ポ" :"PO", 76 | "キャ" :"KYA", 77 | "キュ" :"KYU", 78 | "キョ" :"KYO", 79 | "シャ" :"SHA", 80 | "シュ" :"SHU", 81 | "ショ" :"SHO", 82 | "チャ" :"CHA", 83 | "チュ" :"CHU", 84 | "チョ" :"CHO", 85 | "ニャ" :"NYA", 86 | "ニュ" :"NYU", 87 | "ニョ" :"NYO", 88 | "ヒャ" :"HYA", 89 | "ヒュ" :"HYU", 90 | "ヒョ" :"HYO", 91 | "ミャ" :"MYA", 92 | "ミュ" :"MYU", 93 | "ミョ" :"MYO", 94 | "ギャ" :"GYA", 95 | "ギュ" :"GYU", 96 | "ギョ" :"GYO", 97 | "ジャ" :"JA", 98 | "ジュ" :"JU", 99 | "ジョ" :"JO", 100 | "ヂャ" :"JA", 101 | "ヂュ" :"JU", 102 | "ヂョ" :"JO", 103 | "ビャ" :"BYA", 104 | "ビュ" :"BYU", 105 | "ビョ" :"BYO", 106 | "ピャ" :"PYA", 107 | "ピュ" :"PYU", 108 | "ピョ" :"PYO", 109 | "ファ" :"FA", 110 | "ァ" :"A", 111 | "ィ" :"I", 112 | "ゥ" :"U", 113 | "ェ" :"E", 114 | "ォ" :"O", 115 | "ッ" :"T", 116 | ] 117 | 118 | name = convert_kana('たなか', 'KC') 119 | 120 | translation = '' 121 | 122 | for (letter in name) { 123 | if (map.has(letter)) { 124 | translation = translation + map[letter] 125 | } 126 | } 127 | 128 | dump(translation) 129 | -------------------------------------------------------------------------------- /csv_upload.ws: -------------------------------------------------------------------------------- 1 | url = var('request.url') 2 | 3 | if (var('$request.method$') != 'POST') { 4 | respond(' 5 | 6 |
{}30 |
31 | Upload again 32 |
33 | '.format(json_encode(array), url)) 34 | -------------------------------------------------------------------------------- /csv_upload_with_form_fields.ws: -------------------------------------------------------------------------------- 1 | url = var('request.url') 2 | set_header('content-type', 'text/html'); 3 | 4 | // Display file upload form and exit if HTTP method is not POST 5 | if (var('request.method') != 'POST') { 6 | respond(' 7 | 8 |Date: {}
55 |Comment: {}
56 |{}57 |
58 | Upload again 59 |
60 | '.format( 61 | var('request.form.date', 'No date supplied'), 62 | var('request.form.comment', 'No comment supplied'), 63 | json_encode(array), 64 | url 65 | )) 66 | -------------------------------------------------------------------------------- /date_compare.ws: -------------------------------------------------------------------------------- 1 | date1 = '2022-01-15' 2 | 3 | datea = '2022-01-14' 4 | dateb = '2022-01-01' 5 | 6 | sevenDays = 604800; 7 | 8 | if (date_interval(datea, date1) > sevenDays) { 9 | echo('Date A is earlier than 7 days') 10 | } 11 | 12 | if (date_interval(dateb, date1) > sevenDays) { 13 | echo('Date B is earlier than 7 days') 14 | } 15 | -------------------------------------------------------------------------------- /date_response.ws: -------------------------------------------------------------------------------- 1 | slot01 = "next monday 9am".to_date() 2 | slot01date = date_format(slot01, 'DD-MM-YYYY') 3 | 4 | template = '{"records":[{"Slot":"Slot 01","Day":"Monday","Time":"{}","Date":"{}"}]}'; 5 | 6 | respond( 7 | template.format( 8 | slot01, 9 | slot01date 10 | ), 11 | 200, 12 | ['Content-Type: application/json'] 13 | ); 14 | -------------------------------------------------------------------------------- /expiry.ws: -------------------------------------------------------------------------------- 1 | expiry_dates = [ 2 | 'item1': [ 3 | 'expiry': '2021-08-01T00:00:00.000000Z', 4 | 'url': 'https://example.com', 5 | ], 6 | 'item2': [ 7 | 'expiry': '2021-02-01T00:00:00.000000Z', 8 | 'url': 'https://example.com', 9 | ], 10 | ] 11 | 12 | itemId = var('request.query.item', '') 13 | 14 | if (!expiry_dates.has(itemId)) { 15 | respond('Item not found', 404) 16 | } 17 | 18 | item = expiry_dates[itemId] 19 | 20 | interval = date_interval(to_date('now'), item['expiry']) 21 | 22 | if (interval < 0) { 23 | respond('Item expired', 404) 24 | } 25 | 26 | respond('The link is ' + item['url']) 27 | -------------------------------------------------------------------------------- /hello_world.ws: -------------------------------------------------------------------------------- 1 | echo('Hello World!'); 2 | 3 | return 'value'; 4 | -------------------------------------------------------------------------------- /multipart_file_upload.ws: -------------------------------------------------------------------------------- 1 | requestUrl = 'https://example.com/api/upload-file' 2 | 3 | multiPartTemplate = ' 4 | --{} 5 | 6 | Content-Disposition: form-data; name="file[]"; filename="{}" 7 | Content-Type: {} 8 | 9 | {} 10 | 11 | --{}' 12 | multiPartBoundary = '_BOUNDARY_' 13 | 14 | requestBody = '' 15 | requestMethod = 'POST' 16 | requestHeaders = [ 17 | 'Content-Type: multipart/form-data; boundary='+multiPartBoundary, 18 | ] 19 | 20 | for (file in files()) { 21 | requestBody = requestBody + multiPartTemplate.format( 22 | multiPartBoundary, 23 | file['filename'], 24 | file['content_type'], 25 | file_content(file['id']), 26 | multiPartBoundary 27 | ) 28 | } 29 | 30 | request(requestUrl, requestBody, requestMethod, requestHeaders, true) 31 | -------------------------------------------------------------------------------- /multipart_form.ws: -------------------------------------------------------------------------------- 1 | formFields = [ 2 | 'mykey': 'myvalue', 3 | 'anotherkey': 'anothervalue' 4 | ] 5 | 6 | requestUrl = 'https://example.com' 7 | requestMethod = 'POST' 8 | multiPartBoundary = '_BOUNDARY_' 9 | requestHeaders = [ 10 | 'Content-Type: multipart/form-data; boundary='+multiPartBoundary, 11 | ] 12 | 13 | multiPartTemplate = ' 14 | --{} 15 | 16 | Content-Disposition: form-data; name="{}"; 17 | 18 | {} 19 | 20 | --{}' 21 | 22 | requestBody = '' 23 | 24 | for (field in formFields.keys()) { 25 | requestBody = requestBody + multiPartTemplate.format( 26 | multiPartBoundary, 27 | field, 28 | formFields[field], 29 | multiPartBoundary 30 | ) 31 | } 32 | 33 | request(requestUrl, requestBody, requestMethod, requestHeaders, true) 34 | -------------------------------------------------------------------------------- /rate_limit.ws: -------------------------------------------------------------------------------- 1 | last_action = var('last_action') 2 | current_time = to_date('now') 3 | 4 | function update_last_action() { 5 | store('last_action', current_time) 6 | } 7 | 8 | if (!last_action) { 9 | update_last_action() 10 | } 11 | 12 | interval = date_interval(last_action, current_time); 13 | 14 | if (interval < 5) { 15 | respond('ERROR: Less than 5 seconds passed between last action', 429) 16 | } 17 | 18 | update_last_action() 19 | respond('OK: Within rate limit') 20 | -------------------------------------------------------------------------------- /return_latest_post_on_get.ws: -------------------------------------------------------------------------------- 1 | if (var('request.method') == 'POST') { 2 | store('latest_request', var('request.content')); 3 | } else { 4 | latest = var('latest_request'); 5 | if (latest) { 6 | set_response(latest); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /twilio.ws: -------------------------------------------------------------------------------- 1 | // Send an SMS with Twilio using WebhookScript 2 | 3 | accountId = 'ACdXXXXX' 4 | secret = '7fc199XXXXX' 5 | 6 | body = query([ 7 | 'From': 'test', 8 | 'Body': 'Hello World', 9 | 'To': '+45 28254197', 10 | ]) 11 | 12 | resp = request( 13 | 'https://api.twilio.com/2010-04-01/Accounts/' + accountId + '/Messages.json', 14 | body, 15 | 'POST', 16 | [ 17 | 'Content-Type: application/x-www-form-urlencoded', 18 | 'Authorization: Basic ' + base64_encode(accountId + ':' + secret) 19 | ] 20 | ) 21 | -------------------------------------------------------------------------------- /upload_files_from_json_to_dropbox.ws: -------------------------------------------------------------------------------- 1 | // Change this to your dropbox provider ID from here: https://webhook.site/providers 2 | providerId = 19 3 | 4 | files = json_path(var('request.content'), '.FlyerFile.*') 5 | 6 | for (fileInfo in files) { 7 | 8 | // Download file from URL 9 | fileDownload = request(fileInfo['File']) 10 | 11 | // Check if file link invalid or expired 12 | if (fileDownload['status'] != 200) { 13 | echo( 14 | 'Could not upload /FlyerFiles/%s, got status %s'.format( 15 | fileInfo['Name'], 16 | fileDownload['status'] 17 | ) 18 | ) 19 | continue 20 | } 21 | 22 | // Execute Dropbox Upload File action 23 | action( 24 | 'dropbox_upload_file', 25 | [ 26 | 'path': '/FlyerFiles/%s'.format(fileInfo['Name']), 27 | 'body': fileDownload['content'], 28 | 'mode': 'update', 29 | 'provider_id': providerId 30 | ] 31 | ) 32 | 33 | echo('Uploaded /FlyerFiles/%s'.format(fileInfo['Name'])) 34 | 35 | } 36 | --------------------------------------------------------------------------------