Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle libs internaly; implement twilio over http lib #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

itayd
Copy link
Contributor

@itayd itayd commented Apr 1, 2024

No description provided.

@@ -0,0 +1,65 @@
_BASE_URL = "https://api.twilio.com/2010-04-01"

def connect(conn, account_sid, auth_token=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a python reference for twilio sdk, I think we should stick with this standard instead of the connect option (rename connect to Client or NewClient)

from twilio.rest import Client

# Your Account SID and Auth Token from console.twilio.com
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"

client = Client(account_sid, auth_token)

message = client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="Hello from Python!")

print(message.sid)

Comment on lines +6 to +21
def _url(path):
return _BASE_URL + path

def _post(path, body):
resp = conn.post(
_url(path),
form_body=body,
basic_auth=auth_token and (account_sid, auth_token) or None,
)

json = resp.body.json()

if resp.status_code < 200 or resp.status_code >= 400:
fail(json)

return json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is probably shared utils for all http clients, can be lib/integrations/http
usable by itself
small effort to split it now and we can get a lot by reusing it

@@ -0,0 +1,16 @@
load("env", "TWILIO_ACCOUNT_SID", "TWILIO_AUTH_TOKEN", "TWILIO_MSG_SERVICE_SID")
load("libs/integrations/twilio.star", "twilio")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a predefined lib,
I think we can try (in a different ticket in the future) to add "libs" or "plugins" section to the manifest, and inject this code automatically

so

project:
  libs:
    - name: twilio
      source: github/.... (optional, only if name is not auto resolved by ak core)
       data:
         account_sid: (from secret)
         twilio_auth_token: (from secret)

then the script can just declare what it needs and start using it
without loading env and lib and setting up a client (although it can)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants