Code Monkey home page Code Monkey logo

courier-python's People

Contributors

andrewmilas10 avatar armandobelardo avatar aydrian avatar bwebs avatar cgradwohl avatar drew-y avatar dsinghvi avatar fern-api[bot] avatar fern-bot avatar jackwestmoretab avatar jrweingart avatar lednax avatar suhasdeshpande avatar tk26 avatar vatasha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

courier-python's Issues

Unable to create SendStep properly in ad hoc automation

Tried to create ad hoc automation with delay and send steps, but not sure how can I pass to in send step to point email of recipient. I noticed in the code that this step can receive profile - is this the way to pass recipient email? This is the code I am using:

import courier
from courier.client import Courier

...

response = client.automations.invoke_ad_hoc_automation(
            request = courier.AutomationAdHocInvokeParams(
                data = {
                    'email': data['email'],
                    'cancelation_token': cancelation_token
                },
                automation = courier.Automation(
                    cancelation_token=cancelation_token,
                    steps=[
                      courier.AutomationDelayStep(
                          action="delay",
                          duration="48 hours"
                      ),
                      courier.AutomationSendStep(
                          profile={"email": data["email"]},
                          template=template,
                          action="send",
                          data=data['template_data']
                      )
                  ]
                )
            )
        )

Running it receive this error:

status_code: 400, body: {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}, {'status_code': 400, 'body': {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}}

`Messages.get` does not work when delivered/opened/clicked are empty.

3 validation errors for ParsingModel[MessageDetails]
__root__ -> delivered
  field required (type=value_error.missing)
__root__ -> opened
  field required (type=value_error.missing)
__root__ -> clicked
  field required (type=value_error.missing)

@


    def get(self, message_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> MessageDetails:
        # ....
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(MessageDetails, _response.json())  # type: ignore
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ problematic line

SubscriptionTopic pydantic model doesn't require the `status` attribute when it should

I was able to create a SubscriptionTopic pydantic model instance with only the id argument set, but this is not accepted by the create_or_replace API for the Tenants client:

from courier import DefaultPreferences, SubscriptionTopic
from courier import Client
client = Courier(authorization_token="******")
client.tenants.create_or_replace(tenant_id="org_asdf", name="foobaz")

client.tenants.create_or_replace(
    tenant_id="org_asdf",
    name="foobaz",
    default_preferences=DefaultPreferences(items=[SubscriptionTopic(id="foo")])
)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/courier/tenants/client.py", line 117, in create_or_replace
    raise BadRequestError(pydantic_v1.parse_obj_as(BadRequest, _response.json()))  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
courier.commons.errors.bad_request_error.BadRequestError: status_code: 400, body: message='[{"error":"/default_preferences/items/0 must have required property \'status\'","path":"/default_preferences/items/0"}]' type='invalid_request_error'

The create or replace API docs specify that the status field is required for a SubscriptionTopic: https://www.courier.com/docs/reference/tenants/create-replace/

The Pydantic model should be updated to require the status field so it matches the REST API.

This was observed while using trycourier = "6.0.2".

Tenants client `list_` method always returns a `TenantListResponse` with an empty `items`

I am attempting to list my tenants, but the issue I am running into is that the TenantListResponse has an empty items in the response. It appears it is supposed to return a list of Tenant objects in the items attribute, but this is always empty. This is the case even when the has_more attribute is True, indicating the list was paginated and I can retrieve more tenants. Passing the resulting cursor also returns a TenantListResponse with an empty items.

>>> client = Courier(authorization_token=courier_api_key)
>>> tenants = client.tenants.list_()
>>> tenants
TenantListResponse(cursor='MTcxODMxODc1MzkyMSxNR0prWlRZME5EQXRZV1prTXkwMFpHRXpMVGd4WkdRdE1tVmtZamcxT1RoaE9EaGlMM1JsYzNRdmIzSm5YelZLYTFocVNsWmtRMlpZWTJKM1NFOUVVazFNVmpKcmFFRnNjQT09', has_more=True, items=[], next_url='/tenants?cursor=MTcxODMxODc1MzkyMSxNR0prWlRZME5EQXRZV1prTXkwMFpHRXpMVGd4WkdRdE1tVmtZamcxT1RoaE9EaGlMM1JsYzNRdmIzSm5YelZLYTFocVNsWmtRMlpZWTJKM1NFOUVVazFNVmpKcmFFRnNjQT09', url='/tenants', type='list')
>>> tenants.has_more
True
>>> tenants.items
[]

How to send notification to another user's slack workspace

I want to send slack notification (message as an app to another workspace).

  1. I have created a slack app as slack_app
  2. I have installed slack_app into my own_workspace as own_ws.
  3. A external users say user_x has installed my slack app into their workspace.

I want to automate this sending notification business using third parties for example, using courier or using something else library.

I have webhook url of user_x's slack workspace which i caught during oauth installation and that is something can be used to send messages but how to automate this sending notification via some third party.

How we can send notification/message into another workspace ? I did research a bit but could not find relevant information anywhere.

Sorry that creating this an issue, It is Question/discussion label. I could not find anything, hence posted here for some positive response.

Tenants client `create_or_replace` requires default_preferences when it should not

The behavior of create_or_replace for the Tenants client does not match the REST API nor its Python method signature.

When I attempt to create a tenant without specifying default_preferences, I get the following error:

from courier import Client
client = Courier(authorization_token="******")
client.tenants.create_or_replace(tenant_id="org_asdf", name="foobaz")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/courier/tenants/client.py", line 115, in create_or_replace
    return pydantic_v1.parse_obj_as(Tenant, _response.json())  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/pydantic/v1/tools.py", line 38, in parse_obj_as
    return model_type(__root__=obj).__root__
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ParsingModel[Tenant]
__root__ -> default_preferences -> items
  field required (type=value_error.missing)

This same call to the REST API directly works fine.

The API documentation here states that default_preferences are not required, which also matches the Python method signature: https://www.courier.com/docs/reference/tenants/create-replace/

This was observed with trycourier = "6.0.2".

lists.add_subscribers is incorrectly encoding the request body

Trying to add recipients to a list and have followed the included example but a bad request error is returned. Best I can tell, the request data isn't getting encoded properly to the expected format from the API.

"name": "BadRequestError",
"message": "status_code: 400, body: message=' type must be object' type='invalid_request_error'",
"stack": "---------------------------------------------------------------------------
BadRequestError                           Traceback (most recent call last)
Cell In[26], line 1
----> 1 client.lists.add_subscribers(
      2     list_id="undelivered",
      3     request=[PutSubscriptionsRecipient(recipient_id="1354820")]
      4 )

File d:\\dev\\courierPy\\venv\\lib\\site-packages\\courier\\lists\\client.py:708, in ListsClient.add_subscribers(self, list_id, request, idempotency_key, idempotency_expiry, request_options)
    706     return
    707 if _response.status_code == 400:
--> 708     raise BadRequestError(pydantic_v1.parse_obj_as(BadRequest, _response.json()))  # type: ignore
    709 try:
    710     _response_json = _response.json()

BadRequestError: status_code: 400, body: message=' type must be object' type='invalid_request_error'"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.