Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a1eb73115 | |||
| 81e39e8148 | |||
| d06ea406d3 |
@@ -0,0 +1,72 @@
|
|||||||
|
id: hibp
|
||||||
|
name: Have I Been Pwned
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Have I Been Pwned (API v3 + Pwned Passwords) — breach enrichment: check an email for breaches and pastes, list and read breaches, and check whether a password appears in breaches (k-anonymity, password never sent). API-key authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: account breaches/pastes, list/get breach, password pwned check."
|
||||||
|
category: enrichment
|
||||||
|
|
||||||
|
# Per-instance configuration. The API key is sent as the 'hibp-api-key' header
|
||||||
|
# (required for account lookups). A User-Agent is always sent, as HIBP requires.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
api_key:
|
||||||
|
type: string
|
||||||
|
description: "Have I Been Pwned API key"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
required:
|
||||||
|
- api_key
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: account_breaches
|
||||||
|
name: hibp-account-breaches
|
||||||
|
description: "Get the breaches an email address appears in."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
email: { type: string, description: "Email address to check" }
|
||||||
|
required: [email]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: account_pastes
|
||||||
|
name: hibp-account-pastes
|
||||||
|
description: "Get the pastes an email address appears in."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
email: { type: string, description: "Email address to check" }
|
||||||
|
required: [email]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_breaches
|
||||||
|
name: hibp-list-breaches
|
||||||
|
description: "List all breaches in the system (optionally filtered by domain)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
domain: { type: string, description: "Optional domain filter" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_breach
|
||||||
|
name: hibp-get-breach
|
||||||
|
description: "Get the details of a single breach by name."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
name: { type: string, description: "Breach name (e.g. Adobe)" }
|
||||||
|
required: [name]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: password_pwned
|
||||||
|
name: hibp-password-pwned
|
||||||
|
description: "Check whether a password appears in known breaches (via k-anonymity; the password itself is never transmitted)."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
password: { type: string, description: "The password to check" }
|
||||||
|
required: [password]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: hibp-test-connection
|
||||||
|
description: "Verify the API key (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
email = inputs.get("email")
|
||||||
|
if not email:
|
||||||
|
raise Exception("email is required")
|
||||||
|
try:
|
||||||
|
result = request("/breachedaccount/" + q(email), cfg, params={"truncateResponse": "false"})
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
if e.code == 404:
|
||||||
|
return {"email": email, "breaches": []}
|
||||||
|
raise
|
||||||
|
return {"email": email, "breaches": result}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
email = inputs.get("email")
|
||||||
|
if not email:
|
||||||
|
raise Exception("email is required")
|
||||||
|
try:
|
||||||
|
result = request("/pasteaccount/" + q(email), cfg)
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
if e.code == 404:
|
||||||
|
return {"email": email, "pastes": []}
|
||||||
|
raise
|
||||||
|
return {"email": email, "pastes": result}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
name = inputs.get("name")
|
||||||
|
if not name:
|
||||||
|
raise Exception("name is required")
|
||||||
|
result = request("/breach/" + q(name), cfg)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
domain = inputs.get("domain")
|
||||||
|
result = request("/breaches", cfg, params={"domain": domain})
|
||||||
|
return {"breaches": result}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
password = inputs.get("password")
|
||||||
|
if not password:
|
||||||
|
raise Exception("password is required")
|
||||||
|
|
||||||
|
sha1 = hashlib.sha1(password.encode("utf-8")).hexdigest().upper()
|
||||||
|
prefix = sha1[:5]
|
||||||
|
suffix = sha1[5:]
|
||||||
|
|
||||||
|
url = "https://api.pwnedpasswords.com/range/" + prefix
|
||||||
|
req = urllib.request.Request(url, headers={"User-Agent": "Riposte-SOAR"}, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
body = r.read().decode("utf-8", "replace")
|
||||||
|
|
||||||
|
for line in body.splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if not line or ":" not in line:
|
||||||
|
continue
|
||||||
|
line_suffix, count = line.split(":", 1)
|
||||||
|
if line_suffix.strip().upper() == suffix.upper():
|
||||||
|
return {"pwned": True, "count": int(count.strip())}
|
||||||
|
|
||||||
|
return {"pwned": False, "count": 0}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import json, os, sys, hashlib, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
BASE = "https://haveibeenpwned.com/api/v3"
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def request(path, cfg, params=None):
|
||||||
|
url = BASE + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
headers = {"hibp-api-key": str(cfg.get("api_key", "")), "User-Agent": "Riposte-SOAR", "Accept": "application/json"}
|
||||||
|
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
request("/breaches", cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
id: telegram
|
||||||
|
name: Telegram
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Telegram Bot API — SOC alerting via a bot: send text messages and photos to a chat, read chat info, and poll updates. Bot-token authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: send message, send photo, get chat, get updates."
|
||||||
|
category: notification
|
||||||
|
|
||||||
|
# Per-instance configuration. The bot token is placed in the API path
|
||||||
|
# (https://api.telegram.org/bot<token>/...).
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
bot_token:
|
||||||
|
type: string
|
||||||
|
description: "Telegram bot token (from BotFather)"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
default_chat_id:
|
||||||
|
type: string
|
||||||
|
description: "Default chat ID to send to (optional)"
|
||||||
|
required:
|
||||||
|
- bot_token
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: send_message
|
||||||
|
name: telegram-send-message
|
||||||
|
description: "Send a text message to a chat."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
chat_id: { type: string, description: "Chat ID (overrides the configured default)" }
|
||||||
|
text: { type: string, description: "Message text" }
|
||||||
|
parse_mode: { type: string, description: "Optional: Markdown or HTML" }
|
||||||
|
required: [text]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: send_photo
|
||||||
|
name: telegram-send-photo
|
||||||
|
description: "Send a photo (by URL) to a chat."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
chat_id: { type: string, description: "Chat ID (overrides the configured default)" }
|
||||||
|
photo: { type: string, description: "Photo URL" }
|
||||||
|
caption: { type: string, description: "Optional caption" }
|
||||||
|
required: [photo]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_chat
|
||||||
|
name: telegram-get-chat
|
||||||
|
description: "Get information about a chat."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
chat_id: { type: string, description: "Chat ID (overrides the configured default)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_updates
|
||||||
|
name: telegram-get-updates
|
||||||
|
description: "Poll recent updates (incoming messages) for the bot."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
limit: { type: number, description: "Max updates (default 20)" }
|
||||||
|
offset: { type: number, description: "Update offset (optional)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: telegram-test-connection
|
||||||
|
description: "Verify the bot token (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.telegram.org/bot" + str(cfg.get("bot_token", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def call(method_name, cfg, body=None, params=None, http="POST"):
|
||||||
|
url = _base(cfg) + "/" + method_name
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=http)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
resp = json.loads(r.read() or "{}")
|
||||||
|
if not resp.get("ok"):
|
||||||
|
raise Exception("Telegram error: " + json.dumps(resp))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_chat = lambda cfg, inputs: (inputs.get("chat_id") or cfg.get("default_chat_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
chat = _chat(cfg, inputs)
|
||||||
|
if not chat:
|
||||||
|
raise Exception("chat_id is required (set a default or pass one)")
|
||||||
|
|
||||||
|
resp = call("getChat", cfg, params={"chat_id": chat}, http="GET")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.telegram.org/bot" + str(cfg.get("bot_token", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def call(method_name, cfg, body=None, params=None, http="POST"):
|
||||||
|
url = _base(cfg) + "/" + method_name
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=http)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
resp = json.loads(r.read() or "{}")
|
||||||
|
if not resp.get("ok"):
|
||||||
|
raise Exception("Telegram error: " + json.dumps(resp))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_chat = lambda cfg, inputs: (inputs.get("chat_id") or cfg.get("default_chat_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
limit = inputs.get("limit")
|
||||||
|
offset = inputs.get("offset")
|
||||||
|
|
||||||
|
params = {"limit": int(limit or 20)}
|
||||||
|
if offset not in (None, ""):
|
||||||
|
params["offset"] = int(offset)
|
||||||
|
|
||||||
|
resp = call("getUpdates", cfg, params=params, http="GET")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.telegram.org/bot" + str(cfg.get("bot_token", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def call(method_name, cfg, body=None, params=None, http="POST"):
|
||||||
|
url = _base(cfg) + "/" + method_name
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=http)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
resp = json.loads(r.read() or "{}")
|
||||||
|
if not resp.get("ok"):
|
||||||
|
raise Exception("Telegram error: " + json.dumps(resp))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_chat = lambda cfg, inputs: (inputs.get("chat_id") or cfg.get("default_chat_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
chat = _chat(cfg, inputs)
|
||||||
|
if not chat:
|
||||||
|
raise Exception("chat_id is required (set a default or pass one)")
|
||||||
|
|
||||||
|
text = inputs.get("text")
|
||||||
|
if not text:
|
||||||
|
raise Exception("text is required")
|
||||||
|
|
||||||
|
parse_mode = inputs.get("parse_mode")
|
||||||
|
|
||||||
|
body = {"chat_id": chat, "text": text}
|
||||||
|
if parse_mode:
|
||||||
|
body["parse_mode"] = parse_mode
|
||||||
|
|
||||||
|
resp = call("sendMessage", cfg, body=body)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.telegram.org/bot" + str(cfg.get("bot_token", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def call(method_name, cfg, body=None, params=None, http="POST"):
|
||||||
|
url = _base(cfg) + "/" + method_name
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=http)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
resp = json.loads(r.read() or "{}")
|
||||||
|
if not resp.get("ok"):
|
||||||
|
raise Exception("Telegram error: " + json.dumps(resp))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_chat = lambda cfg, inputs: (inputs.get("chat_id") or cfg.get("default_chat_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
chat = _chat(cfg, inputs)
|
||||||
|
if not chat:
|
||||||
|
raise Exception("chat_id is required (set a default or pass one)")
|
||||||
|
|
||||||
|
photo = inputs.get("photo")
|
||||||
|
if not photo:
|
||||||
|
raise Exception("photo is required")
|
||||||
|
|
||||||
|
caption = inputs.get("caption")
|
||||||
|
|
||||||
|
body = {"chat_id": chat, "photo": photo}
|
||||||
|
if caption:
|
||||||
|
body["caption"] = caption
|
||||||
|
|
||||||
|
resp = call("sendPhoto", cfg, body=body)
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import json, os, sys, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.telegram.org/bot" + str(cfg.get("bot_token", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def call(method_name, cfg, body=None, params=None, http="POST"):
|
||||||
|
url = _base(cfg) + "/" + method_name
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = json.dumps(body).encode("utf-8") if body is not None else None
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if data is not None:
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=http)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
resp = json.loads(r.read() or "{}")
|
||||||
|
if not resp.get("ok"):
|
||||||
|
raise Exception("Telegram error: " + json.dumps(resp))
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_chat = lambda cfg, inputs: (inputs.get("chat_id") or cfg.get("default_chat_id"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
resp = call("getMe", cfg, http="GET")
|
||||||
|
return {"ok": True, "bot": resp.get("result", {}).get("username")}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
id: twilio
|
||||||
|
name: Twilio
|
||||||
|
version: 1.0.0
|
||||||
|
description: "Twilio (REST API) — SOC out-of-band alerting: send SMS messages, place voice calls, and read message status/history. HTTP Basic authentication; stdlib-only, no extra Python dependencies."
|
||||||
|
changelog: "1.0.0 — Initial release: send SMS, make call, get/list messages."
|
||||||
|
category: notification
|
||||||
|
|
||||||
|
# Per-instance configuration. HTTP Basic auth with the Account SID + Auth Token.
|
||||||
|
config_schema:
|
||||||
|
properties:
|
||||||
|
account_sid:
|
||||||
|
type: string
|
||||||
|
description: "Twilio Account SID"
|
||||||
|
auth_token:
|
||||||
|
type: string
|
||||||
|
description: "Twilio Auth Token"
|
||||||
|
x-soar-sensitive: true
|
||||||
|
from_number:
|
||||||
|
type: string
|
||||||
|
description: "Default sender number (E.164, e.g. +15551234567)"
|
||||||
|
required:
|
||||||
|
- account_sid
|
||||||
|
- auth_token
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- id: send_sms
|
||||||
|
name: twilio-send-sms
|
||||||
|
description: "Send an SMS message."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
to: { type: string, description: "Recipient number (E.164)" }
|
||||||
|
body: { type: string, description: "Message text" }
|
||||||
|
from_number: { type: string, description: "Sender number (overrides the configured default)" }
|
||||||
|
required: [to, body]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: make_call
|
||||||
|
name: twilio-make-call
|
||||||
|
description: "Place a voice call that plays TwiML."
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
to: { type: string, description: "Recipient number (E.164)" }
|
||||||
|
from_number: { type: string, description: "Caller number (overrides the configured default)" }
|
||||||
|
twiml: { type: string, description: "TwiML to execute (provide this or url)" }
|
||||||
|
url: { type: string, description: "URL returning TwiML (provide this or twiml)" }
|
||||||
|
required: [to]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: get_message
|
||||||
|
name: twilio-get-message
|
||||||
|
description: "Get a message's status and details by SID."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
message_sid: { type: string, description: "Message SID" }
|
||||||
|
required: [message_sid]
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
- id: list_messages
|
||||||
|
name: twilio-list-messages
|
||||||
|
description: "List recent messages."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties:
|
||||||
|
page_size: { type: number, description: "Max messages (default 20)" }
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
|
|
||||||
|
- id: test_connection
|
||||||
|
name: twilio-test-connection
|
||||||
|
description: "Verify connectivity and credentials (used by the Test button)."
|
||||||
|
risk: read
|
||||||
|
inputs_schema:
|
||||||
|
properties: {}
|
||||||
|
required: []
|
||||||
|
outputs_schema: { properties: {} }
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.twilio.com/2010-04-01/Accounts/" + str(cfg.get("account_sid", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
raw = str(cfg.get("account_sid", "")) + ":" + str(cfg.get("auth_token", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None, params=None):
|
||||||
|
url = _base(cfg) + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode({k: v for k, v in form.items() if v not in (None, "")}).encode("utf-8")
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
_from = lambda cfg, inputs: (inputs.get("from_number") or cfg.get("from_number"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
message_sid = inputs.get("message_sid")
|
||||||
|
if not message_sid:
|
||||||
|
raise Exception("message_sid is required")
|
||||||
|
return request("GET", "/Messages/" + q(message_sid) + ".json", cfg)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.twilio.com/2010-04-01/Accounts/" + str(cfg.get("account_sid", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
raw = str(cfg.get("account_sid", "")) + ":" + str(cfg.get("auth_token", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None, params=None):
|
||||||
|
url = _base(cfg) + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode({k: v for k, v in form.items() if v not in (None, "")}).encode("utf-8")
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
_from = lambda cfg, inputs: (inputs.get("from_number") or cfg.get("from_number"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
page_size = inputs.get("page_size")
|
||||||
|
return request("GET", "/Messages.json", cfg, params={"PageSize": int(page_size or 20)})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.twilio.com/2010-04-01/Accounts/" + str(cfg.get("account_sid", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
raw = str(cfg.get("account_sid", "")) + ":" + str(cfg.get("auth_token", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None, params=None):
|
||||||
|
url = _base(cfg) + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode({k: v for k, v in form.items() if v not in (None, "")}).encode("utf-8")
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
_from = lambda cfg, inputs: (inputs.get("from_number") or cfg.get("from_number"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
to = inputs.get("to")
|
||||||
|
if not to:
|
||||||
|
raise Exception("to is required")
|
||||||
|
frm = _from(cfg, inputs)
|
||||||
|
if not frm:
|
||||||
|
raise Exception("from_number is required (set a default or pass one)")
|
||||||
|
twiml = inputs.get("twiml")
|
||||||
|
url = inputs.get("url")
|
||||||
|
if not twiml and not url:
|
||||||
|
raise Exception("twiml or url is required")
|
||||||
|
form = {"From": frm, "To": to}
|
||||||
|
if twiml:
|
||||||
|
form["Twiml"] = twiml
|
||||||
|
elif url:
|
||||||
|
form["Url"] = url
|
||||||
|
return request("POST", "/Calls.json", cfg, form=form)
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.twilio.com/2010-04-01/Accounts/" + str(cfg.get("account_sid", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
raw = str(cfg.get("account_sid", "")) + ":" + str(cfg.get("auth_token", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None, params=None):
|
||||||
|
url = _base(cfg) + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode({k: v for k, v in form.items() if v not in (None, "")}).encode("utf-8")
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
_from = lambda cfg, inputs: (inputs.get("from_number") or cfg.get("from_number"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
to = inputs.get("to")
|
||||||
|
if not to:
|
||||||
|
raise Exception("to is required")
|
||||||
|
body = inputs.get("body")
|
||||||
|
if not body:
|
||||||
|
raise Exception("body is required")
|
||||||
|
frm = _from(cfg, inputs)
|
||||||
|
if not frm:
|
||||||
|
raise Exception("from_number is required (set a default or pass one)")
|
||||||
|
return request("POST", "/Messages.json", cfg, form={"From": frm, "To": to, "Body": body})
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
|
||||||
|
|
||||||
|
|
||||||
|
def _cfg():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _inputs():
|
||||||
|
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||||
|
|
||||||
|
|
||||||
|
def _base(cfg):
|
||||||
|
return "https://api.twilio.com/2010-04-01/Accounts/" + str(cfg.get("account_sid", ""))
|
||||||
|
|
||||||
|
|
||||||
|
def _auth(cfg):
|
||||||
|
raw = str(cfg.get("account_sid", "")) + ":" + str(cfg.get("auth_token", ""))
|
||||||
|
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, path, cfg, form=None, params=None):
|
||||||
|
url = _base(cfg) + path
|
||||||
|
if params:
|
||||||
|
clean = {k: v for k, v in params.items() if v not in (None, "")}
|
||||||
|
if clean:
|
||||||
|
url += "?" + urllib.parse.urlencode(clean)
|
||||||
|
data = None
|
||||||
|
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
|
||||||
|
if form is not None:
|
||||||
|
data = urllib.parse.urlencode({k: v for k, v in form.items() if v not in (None, "")}).encode("utf-8")
|
||||||
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||||
|
with urllib.request.urlopen(req, timeout=60) as r:
|
||||||
|
raw = r.read()
|
||||||
|
return json.loads(raw) if raw else {}
|
||||||
|
|
||||||
|
|
||||||
|
def _run(fn):
|
||||||
|
try:
|
||||||
|
print(json.dumps(fn(_cfg(), _inputs())))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
q = lambda v: urllib.parse.quote(str(v), safe="")
|
||||||
|
_from = lambda cfg, inputs: (inputs.get("from_number") or cfg.get("from_number"))
|
||||||
|
|
||||||
|
|
||||||
|
def main(cfg, inputs):
|
||||||
|
request("GET", ".json", cfg)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
_run(main)
|
||||||
Reference in New Issue
Block a user