blujay 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- blujay-1.0.0/.gitignore +7 -0
- blujay-1.0.0/CHANGELOG.md +19 -0
- blujay-1.0.0/LICENSE +21 -0
- blujay-1.0.0/PKG-INFO +274 -0
- blujay-1.0.0/README.md +237 -0
- blujay-1.0.0/examples/README.md +8 -0
- blujay-1.0.0/examples/send_message.py +34 -0
- blujay-1.0.0/examples/webhook_server.py +53 -0
- blujay-1.0.0/pyproject.toml +55 -0
- blujay-1.0.0/reference.md +5669 -0
- blujay-1.0.0/src/blujay/__init__.py +1198 -0
- blujay-1.0.0/src/blujay/_default_clients.py +30 -0
- blujay-1.0.0/src/blujay/_errors.py +105 -0
- blujay-1.0.0/src/blujay/_version.py +2 -0
- blujay-1.0.0/src/blujay/attachments/__init__.py +40 -0
- blujay-1.0.0/src/blujay/attachments/client.py +374 -0
- blujay-1.0.0/src/blujay/attachments/raw_client.py +1058 -0
- blujay-1.0.0/src/blujay/attachments/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/attachments/types/attachment_create_response.py +30 -0
- blujay-1.0.0/src/blujay/attachments/types/attachment_get_response.py +30 -0
- blujay-1.0.0/src/blujay/calls/__init__.py +4 -0
- blujay-1.0.0/src/blujay/calls/client.py +113 -0
- blujay-1.0.0/src/blujay/calls/raw_client.py +263 -0
- blujay-1.0.0/src/blujay/capability/__init__.py +36 -0
- blujay-1.0.0/src/blujay/capability/client.py +152 -0
- blujay-1.0.0/src/blujay/capability/raw_client.py +302 -0
- blujay-1.0.0/src/blujay/capability/types/__init__.py +34 -0
- blujay-1.0.0/src/blujay/capability/types/capability_evaluate_service_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/__init__.py +72 -0
- blujay-1.0.0/src/blujay/chats/client.py +848 -0
- blujay-1.0.0/src/blujay/chats/messages/__init__.py +40 -0
- blujay-1.0.0/src/blujay/chats/messages/client.py +336 -0
- blujay-1.0.0/src/blujay/chats/messages/raw_client.py +652 -0
- blujay-1.0.0/src/blujay/chats/messages/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/chats/messages/types/chat_message_list_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/messages/types/chat_message_send_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/participants/__init__.py +42 -0
- blujay-1.0.0/src/blujay/chats/participants/client.py +355 -0
- blujay-1.0.0/src/blujay/chats/participants/raw_client.py +817 -0
- blujay-1.0.0/src/blujay/chats/participants/types/__init__.py +40 -0
- blujay-1.0.0/src/blujay/chats/participants/types/chat_participant_add_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/participants/types/chat_participant_list_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/participants/types/chat_participant_remove_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/raw_client.py +1913 -0
- blujay-1.0.0/src/blujay/chats/types/__init__.py +44 -0
- blujay-1.0.0/src/blujay/chats/types/chat_create_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/types/chat_get_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/types/chat_leave_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/types/chat_list_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/types/chat_update_response.py +30 -0
- blujay-1.0.0/src/blujay/chats/typing/__init__.py +4 -0
- blujay-1.0.0/src/blujay/chats/typing/client.py +186 -0
- blujay-1.0.0/src/blujay/chats/typing/raw_client.py +453 -0
- blujay-1.0.0/src/blujay/client.py +426 -0
- blujay-1.0.0/src/blujay/contacts/__init__.py +87 -0
- blujay-1.0.0/src/blujay/contacts/client.py +1336 -0
- blujay-1.0.0/src/blujay/contacts/notes/__init__.py +40 -0
- blujay-1.0.0/src/blujay/contacts/notes/client.py +248 -0
- blujay-1.0.0/src/blujay/contacts/notes/raw_client.py +549 -0
- blujay-1.0.0/src/blujay/contacts/notes/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/contacts/notes/types/contact_note_create_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/notes/types/contact_note_list_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/raw_client.py +3005 -0
- blujay-1.0.0/src/blujay/contacts/types/__init__.py +74 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_add_tag_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_assign_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_create_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_get_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_list_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_mark_completed_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_opt_out_address_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_opt_out_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_remove_opt_out_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_search_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_stage.py +5 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_update_response.py +30 -0
- blujay-1.0.0/src/blujay/contacts/types/contact_upsert_response.py +30 -0
- blujay-1.0.0/src/blujay/core/__init__.py +139 -0
- blujay-1.0.0/src/blujay/core/api_error.py +62 -0
- blujay-1.0.0/src/blujay/core/client_wrapper.py +146 -0
- blujay-1.0.0/src/blujay/core/datetime_utils.py +70 -0
- blujay-1.0.0/src/blujay/core/file.py +67 -0
- blujay-1.0.0/src/blujay/core/force_multipart.py +18 -0
- blujay-1.0.0/src/blujay/core/http_client.py +1021 -0
- blujay-1.0.0/src/blujay/core/http_response.py +63 -0
- blujay-1.0.0/src/blujay/core/http_sse/__init__.py +42 -0
- blujay-1.0.0/src/blujay/core/http_sse/_api.py +455 -0
- blujay-1.0.0/src/blujay/core/http_sse/_decoders.py +74 -0
- blujay-1.0.0/src/blujay/core/http_sse/_exceptions.py +7 -0
- blujay-1.0.0/src/blujay/core/http_sse/_models.py +17 -0
- blujay-1.0.0/src/blujay/core/jsonable_encoder.py +145 -0
- blujay-1.0.0/src/blujay/core/logging.py +107 -0
- blujay-1.0.0/src/blujay/core/pagination.py +167 -0
- blujay-1.0.0/src/blujay/core/parse_error.py +36 -0
- blujay-1.0.0/src/blujay/core/pydantic_utilities.py +540 -0
- blujay-1.0.0/src/blujay/core/query_encoder.py +58 -0
- blujay-1.0.0/src/blujay/core/remove_none_from_dict.py +11 -0
- blujay-1.0.0/src/blujay/core/request_options.py +41 -0
- blujay-1.0.0/src/blujay/core/serialization.py +349 -0
- blujay-1.0.0/src/blujay/core/unchecked_base_model.py +505 -0
- blujay-1.0.0/src/blujay/environment.py +7 -0
- blujay-1.0.0/src/blujay/errors/__init__.py +71 -0
- blujay-1.0.0/src/blujay/errors/bad_gateway_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/bad_request_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/conflict_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/content_too_large_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/forbidden_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/internal_server_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/not_found_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/service_unavailable_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/too_many_requests_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/unauthorized_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/unprocessable_entity_error.py +11 -0
- blujay-1.0.0/src/blujay/errors/unsupported_media_type_error.py +11 -0
- blujay-1.0.0/src/blujay/me/__init__.py +34 -0
- blujay-1.0.0/src/blujay/me/client.py +100 -0
- blujay-1.0.0/src/blujay/me/raw_client.py +192 -0
- blujay-1.0.0/src/blujay/me/types/__init__.py +34 -0
- blujay-1.0.0/src/blujay/me/types/me_get_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/__init__.py +69 -0
- blujay-1.0.0/src/blujay/messages/client.py +647 -0
- blujay-1.0.0/src/blujay/messages/raw_client.py +1406 -0
- blujay-1.0.0/src/blujay/messages/reactions/__init__.py +40 -0
- blujay-1.0.0/src/blujay/messages/reactions/client.py +315 -0
- blujay-1.0.0/src/blujay/messages/reactions/raw_client.py +741 -0
- blujay-1.0.0/src/blujay/messages/reactions/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/messages/reactions/types/message_reaction_add_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/reactions/types/message_reaction_remove_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/types/__init__.py +56 -0
- blujay-1.0.0/src/blujay/messages/types/message_edit_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/types/message_get_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/types/message_include.py +5 -0
- blujay-1.0.0/src/blujay/messages/types/message_list_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/types/message_list_thread_order.py +5 -0
- blujay-1.0.0/src/blujay/messages/types/message_list_thread_response.py +30 -0
- blujay-1.0.0/src/blujay/messages/types/message_unsend_response.py +30 -0
- blujay-1.0.0/src/blujay/phone_numbers/__init__.py +54 -0
- blujay-1.0.0/src/blujay/phone_numbers/client.py +203 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/__init__.py +46 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/client.py +402 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/raw_client.py +1065 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/types/__init__.py +44 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/types/phone_number_contact_card_delete_response.py +30 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/types/phone_number_contact_card_get_response.py +30 -0
- blujay-1.0.0/src/blujay/phone_numbers/contact_card/types/phone_number_contact_card_set_response.py +30 -0
- blujay-1.0.0/src/blujay/phone_numbers/raw_client.py +396 -0
- blujay-1.0.0/src/blujay/phone_numbers/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/phone_numbers/types/phone_number_get_response.py +30 -0
- blujay-1.0.0/src/blujay/phone_numbers/types/phone_number_list_response.py +30 -0
- blujay-1.0.0/src/blujay/py.typed +0 -0
- blujay-1.0.0/src/blujay/requests/__init__.py +97 -0
- blujay-1.0.0/src/blujay/requests/audio_part.py +18 -0
- blujay-1.0.0/src/blujay/requests/bubble_effect.py +10 -0
- blujay-1.0.0/src/blujay/requests/chat_icon_input.py +11 -0
- blujay-1.0.0/src/blujay/requests/link_part.py +13 -0
- blujay-1.0.0/src/blujay/requests/media_part.py +18 -0
- blujay-1.0.0/src/blujay/requests/message_effect.py +8 -0
- blujay-1.0.0/src/blujay/requests/message_input.py +33 -0
- blujay-1.0.0/src/blujay/requests/message_part.py +11 -0
- blujay-1.0.0/src/blujay/requests/message_reply_to.py +26 -0
- blujay-1.0.0/src/blujay/requests/screen_effect.py +10 -0
- blujay-1.0.0/src/blujay/requests/text_decoration.py +19 -0
- blujay-1.0.0/src/blujay/requests/text_part.py +16 -0
- blujay-1.0.0/src/blujay/requests/vcard_email_input.py +9 -0
- blujay-1.0.0/src/blujay/requests/vcard_part.py +14 -0
- blujay-1.0.0/src/blujay/requests/vcard_phone_input.py +13 -0
- blujay-1.0.0/src/blujay/requests/webhook_phone_number_filter.py +21 -0
- blujay-1.0.0/src/blujay/requests/workflow_metadata.py +10 -0
- blujay-1.0.0/src/blujay/requests/workflow_metadata_value.py +5 -0
- blujay-1.0.0/src/blujay/team_members/__init__.py +36 -0
- blujay-1.0.0/src/blujay/team_members/client.py +104 -0
- blujay-1.0.0/src/blujay/team_members/raw_client.py +196 -0
- blujay-1.0.0/src/blujay/team_members/types/__init__.py +34 -0
- blujay-1.0.0/src/blujay/team_members/types/team_member_list_assignable_response.py +30 -0
- blujay-1.0.0/src/blujay/types/__init__.py +896 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_leave.py +27 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_leave_operation.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_leave_status.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_metadata_mutation.py +39 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_metadata_mutation_operation.py +7 -0
- blujay-1.0.0/src/blujay/types/accepted_chat_metadata_mutation_status.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation.py +33 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation_operation.py +7 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation_participant.py +24 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation_participant_status.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation_participant_type.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_group_participant_mutation_status.py +7 -0
- blujay-1.0.0/src/blujay/types/accepted_message.py +23 -0
- blujay-1.0.0/src/blujay/types/accepted_message_reaction.py +35 -0
- blujay-1.0.0/src/blujay/types/accepted_message_reaction_operation.py +5 -0
- blujay-1.0.0/src/blujay/types/accepted_message_reaction_reaction.py +27 -0
- blujay-1.0.0/src/blujay/types/accepted_message_reaction_status.py +5 -0
- blujay-1.0.0/src/blujay/types/api_key_credential.py +24 -0
- blujay-1.0.0/src/blujay/types/api_key_credential_status.py +5 -0
- blujay-1.0.0/src/blujay/types/api_key_credential_type.py +5 -0
- blujay-1.0.0/src/blujay/types/api_key_summary.py +22 -0
- blujay-1.0.0/src/blujay/types/api_key_summary_status.py +5 -0
- blujay-1.0.0/src/blujay/types/assignable_team_member_list.py +21 -0
- blujay-1.0.0/src/blujay/types/assigned_team_member.py +23 -0
- blujay-1.0.0/src/blujay/types/attachment.py +30 -0
- blujay-1.0.0/src/blujay/types/attachment_id.py +3 -0
- blujay-1.0.0/src/blujay/types/attachment_status.py +5 -0
- blujay-1.0.0/src/blujay/types/attachment_upload.py +35 -0
- blujay-1.0.0/src/blujay/types/attachment_upload_upload_headers.py +31 -0
- blujay-1.0.0/src/blujay/types/audio_output_part.py +34 -0
- blujay-1.0.0/src/blujay/types/audio_output_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/audio_part.py +31 -0
- blujay-1.0.0/src/blujay/types/audio_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/bubble_effect.py +23 -0
- blujay-1.0.0/src/blujay/types/bubble_effect_name.py +5 -0
- blujay-1.0.0/src/blujay/types/bubble_effect_type.py +5 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_data.py +87 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_data_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_data_outcome.py +7 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_data_type.py +5 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/call_ended_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/call_id.py +3 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data.py +94 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_outcome.py +7 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_recording.py +30 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_recording_kind.py +5 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_summary.py +26 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_summary_status.py +5 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_transcript.py +26 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_transcript_status.py +5 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_data_type.py +5 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/call_recording_ready_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/capability_service_result.py +42 -0
- blujay-1.0.0/src/blujay/types/capability_service_result_service.py +5 -0
- blujay-1.0.0/src/blujay/types/capability_service_result_source.py +5 -0
- blujay-1.0.0/src/blujay/types/chat.py +66 -0
- blujay-1.0.0/src/blujay/types/chat_icon.py +28 -0
- blujay-1.0.0/src/blujay/types/chat_icon_input.py +24 -0
- blujay-1.0.0/src/blujay/types/chat_id.py +3 -0
- blujay-1.0.0/src/blujay/types/chat_list.py +24 -0
- blujay-1.0.0/src/blujay/types/chat_participant.py +8 -0
- blujay-1.0.0/src/blujay/types/chat_service.py +5 -0
- blujay-1.0.0/src/blujay/types/chat_type.py +5 -0
- blujay-1.0.0/src/blujay/types/contact.py +66 -0
- blujay-1.0.0/src/blujay/types/contact_assignment_action_result.py +66 -0
- blujay-1.0.0/src/blujay/types/contact_card_profile.py +52 -0
- blujay-1.0.0/src/blujay/types/contact_card_profile_photo.py +26 -0
- blujay-1.0.0/src/blujay/types/contact_card_profile_photo_content_type.py +5 -0
- blujay-1.0.0/src/blujay/types/contact_card_profile_status.py +5 -0
- blujay-1.0.0/src/blujay/types/contact_id.py +3 -0
- blujay-1.0.0/src/blujay/types/contact_list.py +24 -0
- blujay-1.0.0/src/blujay/types/contact_note.py +39 -0
- blujay-1.0.0/src/blujay/types/contact_note_list.py +24 -0
- blujay-1.0.0/src/blujay/types/contact_note_source.py +5 -0
- blujay-1.0.0/src/blujay/types/contact_search_result.py +21 -0
- blujay-1.0.0/src/blujay/types/contact_stage_action_result.py +66 -0
- blujay-1.0.0/src/blujay/types/contact_suppression.py +27 -0
- blujay-1.0.0/src/blujay/types/contact_suppression_address_type.py +5 -0
- blujay-1.0.0/src/blujay/types/contact_tag_action_result.py +66 -0
- blujay-1.0.0/src/blujay/types/direct_chat_participant.py +37 -0
- blujay-1.0.0/src/blujay/types/direct_chat_participant_type.py +5 -0
- blujay-1.0.0/src/blujay/types/error_envelope.py +35 -0
- blujay-1.0.0/src/blujay/types/error_envelope_status.py +5 -0
- blujay-1.0.0/src/blujay/types/error_object.py +64 -0
- blujay-1.0.0/src/blujay/types/event_id.py +3 -0
- blujay-1.0.0/src/blujay/types/generic_webhook_event.py +46 -0
- blujay-1.0.0/src/blujay/types/generic_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/group_name_webhook_data.py +26 -0
- blujay-1.0.0/src/blujay/types/group_name_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/group_name_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/group_participant.py +39 -0
- blujay-1.0.0/src/blujay/types/group_participant_list.py +21 -0
- blujay-1.0.0/src/blujay/types/group_participant_status.py +5 -0
- blujay-1.0.0/src/blujay/types/group_participant_type.py +5 -0
- blujay-1.0.0/src/blujay/types/group_participant_webhook_data.py +27 -0
- blujay-1.0.0/src/blujay/types/group_participant_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/group_participant_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/group_phone_number.py +46 -0
- blujay-1.0.0/src/blujay/types/group_sendability_reason.py +7 -0
- blujay-1.0.0/src/blujay/types/group_webhook_participant.py +30 -0
- blujay-1.0.0/src/blujay/types/group_webhook_participant_status.py +5 -0
- blujay-1.0.0/src/blujay/types/group_webhook_participant_type.py +5 -0
- blujay-1.0.0/src/blujay/types/link_part.py +26 -0
- blujay-1.0.0/src/blujay/types/link_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/me.py +29 -0
- blujay-1.0.0/src/blujay/types/media_output_part.py +30 -0
- blujay-1.0.0/src/blujay/types/media_output_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/media_part.py +31 -0
- blujay-1.0.0/src/blujay/types/media_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/member_id.py +3 -0
- blujay-1.0.0/src/blujay/types/message.py +159 -0
- blujay-1.0.0/src/blujay/types/message_actionable_failure_code.py +14 -0
- blujay-1.0.0/src/blujay/types/message_degradation.py +25 -0
- blujay-1.0.0/src/blujay/types/message_degradation_code.py +7 -0
- blujay-1.0.0/src/blujay/types/message_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/message_edit_history_entry.py +22 -0
- blujay-1.0.0/src/blujay/types/message_edited_webhook_data.py +64 -0
- blujay-1.0.0/src/blujay/types/message_edited_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/message_edited_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/message_effect.py +8 -0
- blujay-1.0.0/src/blujay/types/message_failure.py +26 -0
- blujay-1.0.0/src/blujay/types/message_failure_code.py +18 -0
- blujay-1.0.0/src/blujay/types/message_id.py +3 -0
- blujay-1.0.0/src/blujay/types/message_input.py +44 -0
- blujay-1.0.0/src/blujay/types/message_input_preferred_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_data.py +88 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_data_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_data_requested_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_data_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_data_status.py +7 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/message_lifecycle_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/message_list.py +24 -0
- blujay-1.0.0/src/blujay/types/message_output_part.py +10 -0
- blujay-1.0.0/src/blujay/types/message_part.py +11 -0
- blujay-1.0.0/src/blujay/types/message_preferred_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_reaction.py +46 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_data.py +95 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_data_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_data_requested_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_data_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_data_status.py +5 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/message_received_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/message_reply_to.py +39 -0
- blujay-1.0.0/src/blujay/types/message_reply_to_info.py +34 -0
- blujay-1.0.0/src/blujay/types/message_sender.py +36 -0
- blujay-1.0.0/src/blujay/types/message_sender_type.py +5 -0
- blujay-1.0.0/src/blujay/types/message_service.py +5 -0
- blujay-1.0.0/src/blujay/types/message_status.py +7 -0
- blujay-1.0.0/src/blujay/types/message_team_member_id.py +10 -0
- blujay-1.0.0/src/blujay/types/message_unsent_scope.py +5 -0
- blujay-1.0.0/src/blujay/types/message_unsent_webhook_data.py +64 -0
- blujay-1.0.0/src/blujay/types/message_unsent_webhook_data_unsent_scope.py +5 -0
- blujay-1.0.0/src/blujay/types/message_unsent_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/message_unsent_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/message_webhook_recipient.py +32 -0
- blujay-1.0.0/src/blujay/types/message_webhook_recipient_type.py +5 -0
- blujay-1.0.0/src/blujay/types/new_message.py +68 -0
- blujay-1.0.0/src/blujay/types/new_message_delivery_status.py +5 -0
- blujay-1.0.0/src/blujay/types/new_message_direction.py +5 -0
- blujay-1.0.0/src/blujay/types/new_message_preferred_service.py +5 -0
- blujay-1.0.0/src/blujay/types/new_message_service.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number.py +79 -0
- blujay-1.0.0/src/blujay/types/phone_number_access_type.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number_assigned_webhook_data.py +29 -0
- blujay-1.0.0/src/blujay/types/phone_number_assigned_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/phone_number_assigned_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number_capabilities.py +26 -0
- blujay-1.0.0/src/blujay/types/phone_number_capabilities_messaging.py +23 -0
- blujay-1.0.0/src/blujay/types/phone_number_capabilities_voice.py +25 -0
- blujay-1.0.0/src/blujay/types/phone_number_health.py +29 -0
- blujay-1.0.0/src/blujay/types/phone_number_health_status.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number_id.py +3 -0
- blujay-1.0.0/src/blujay/types/phone_number_limits.py +34 -0
- blujay-1.0.0/src/blujay/types/phone_number_limits_daily.py +27 -0
- blujay-1.0.0/src/blujay/types/phone_number_limits_new_contacts.py +28 -0
- blujay-1.0.0/src/blujay/types/phone_number_line_type.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number_list.py +21 -0
- blujay-1.0.0/src/blujay/types/phone_number_outbound_policy.py +31 -0
- blujay-1.0.0/src/blujay/types/phone_number_queue.py +26 -0
- blujay-1.0.0/src/blujay/types/phone_number_released_webhook_data.py +29 -0
- blujay-1.0.0/src/blujay/types/phone_number_released_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/phone_number_released_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/phone_number_send_status.py +33 -0
- blujay-1.0.0/src/blujay/types/phone_number_send_status_reason_code.py +7 -0
- blujay-1.0.0/src/blujay/types/phone_number_status.py +5 -0
- blujay-1.0.0/src/blujay/types/reaction_emoji.py +6 -0
- blujay-1.0.0/src/blujay/types/reaction_kind.py +7 -0
- blujay-1.0.0/src/blujay/types/reaction_reactor.py +8 -0
- blujay-1.0.0/src/blujay/types/reaction_reactor_address.py +22 -0
- blujay-1.0.0/src/blujay/types/reaction_reactor_address_type.py +5 -0
- blujay-1.0.0/src/blujay/types/reaction_reactor_phone_number_id.py +23 -0
- blujay-1.0.0/src/blujay/types/reaction_reactor_phone_number_id_type.py +5 -0
- blujay-1.0.0/src/blujay/types/reaction_sticker.py +32 -0
- blujay-1.0.0/src/blujay/types/reaction_type.py +7 -0
- blujay-1.0.0/src/blujay/types/reaction_webhook_data.py +36 -0
- blujay-1.0.0/src/blujay/types/reaction_webhook_data_reaction.py +37 -0
- blujay-1.0.0/src/blujay/types/reaction_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/reaction_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/screen_effect.py +23 -0
- blujay-1.0.0/src/blujay/types/screen_effect_name.py +20 -0
- blujay-1.0.0/src/blujay/types/screen_effect_type.py +5 -0
- blujay-1.0.0/src/blujay/types/success_envelope.py +34 -0
- blujay-1.0.0/src/blujay/types/team_member.py +23 -0
- blujay-1.0.0/src/blujay/types/text_decoration.py +30 -0
- blujay-1.0.0/src/blujay/types/text_decoration_style.py +5 -0
- blujay-1.0.0/src/blujay/types/text_part.py +27 -0
- blujay-1.0.0/src/blujay/types/text_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/trace_id.py +3 -0
- blujay-1.0.0/src/blujay/types/typing_webhook_data.py +39 -0
- blujay-1.0.0/src/blujay/types/typing_webhook_event.py +47 -0
- blujay-1.0.0/src/blujay/types/typing_webhook_event_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/typing_webhook_participant.py +28 -0
- blujay-1.0.0/src/blujay/types/typing_webhook_participant_type.py +5 -0
- blujay-1.0.0/src/blujay/types/vcard.py +38 -0
- blujay-1.0.0/src/blujay/types/vcard_email.py +22 -0
- blujay-1.0.0/src/blujay/types/vcard_email_input.py +22 -0
- blujay-1.0.0/src/blujay/types/vcard_email_input_type.py +5 -0
- blujay-1.0.0/src/blujay/types/vcard_email_type.py +5 -0
- blujay-1.0.0/src/blujay/types/vcard_fields.py +39 -0
- blujay-1.0.0/src/blujay/types/vcard_id.py +3 -0
- blujay-1.0.0/src/blujay/types/vcard_list.py +24 -0
- blujay-1.0.0/src/blujay/types/vcard_part.py +27 -0
- blujay-1.0.0/src/blujay/types/vcard_part_type.py +5 -0
- blujay-1.0.0/src/blujay/types/vcard_phone.py +26 -0
- blujay-1.0.0/src/blujay/types/vcard_phone_input.py +26 -0
- blujay-1.0.0/src/blujay/types/vcard_phone_input_type.py +5 -0
- blujay-1.0.0/src/blujay/types/vcard_phone_type.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_delivery_attempt.py +54 -0
- blujay-1.0.0/src/blujay/types/webhook_delivery_attempt_delivery_mode.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_delivery_attempt_error_code.py +26 -0
- blujay-1.0.0/src/blujay/types/webhook_delivery_attempt_list.py +24 -0
- blujay-1.0.0/src/blujay/types/webhook_delivery_attempt_status.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_envelope.py +51 -0
- blujay-1.0.0/src/blujay/types/webhook_envelope_api_version.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_event.py +620 -0
- blujay-1.0.0/src/blujay/types/webhook_event_type.py +31 -0
- blujay-1.0.0/src/blujay/types/webhook_payload_version.py +7 -0
- blujay-1.0.0/src/blujay/types/webhook_phone_number_filter.py +50 -0
- blujay-1.0.0/src/blujay/types/webhook_phone_number_filter_all.py +18 -0
- blujay-1.0.0/src/blujay/types/webhook_phone_number_filter_selected.py +20 -0
- blujay-1.0.0/src/blujay/types/webhook_replay_accepted.py +25 -0
- blujay-1.0.0/src/blujay/types/webhook_replay_accepted_status.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_subscribable_event_type.py +31 -0
- blujay-1.0.0/src/blujay/types/webhook_subscription.py +38 -0
- blujay-1.0.0/src/blujay/types/webhook_subscription_id.py +3 -0
- blujay-1.0.0/src/blujay/types/webhook_subscription_list.py +24 -0
- blujay-1.0.0/src/blujay/types/webhook_subscription_status.py +5 -0
- blujay-1.0.0/src/blujay/types/webhook_subscription_with_secret.py +43 -0
- blujay-1.0.0/src/blujay/types/workflow.py +22 -0
- blujay-1.0.0/src/blujay/types/workflow_id.py +3 -0
- blujay-1.0.0/src/blujay/types/workflow_list.py +21 -0
- blujay-1.0.0/src/blujay/types/workflow_metadata.py +10 -0
- blujay-1.0.0/src/blujay/types/workflow_metadata_value.py +5 -0
- blujay-1.0.0/src/blujay/types/workflow_run_summary.py +24 -0
- blujay-1.0.0/src/blujay/types/workflow_trigger.py +32 -0
- blujay-1.0.0/src/blujay/types/workspace_id.py +3 -0
- blujay-1.0.0/src/blujay/vcards/__init__.py +44 -0
- blujay-1.0.0/src/blujay/vcards/client.py +578 -0
- blujay-1.0.0/src/blujay/vcards/raw_client.py +1191 -0
- blujay-1.0.0/src/blujay/vcards/types/__init__.py +42 -0
- blujay-1.0.0/src/blujay/vcards/types/vcard_create_response.py +30 -0
- blujay-1.0.0/src/blujay/vcards/types/vcard_get_response.py +30 -0
- blujay-1.0.0/src/blujay/vcards/types/vcard_list_response.py +30 -0
- blujay-1.0.0/src/blujay/vcards/types/vcard_update_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/__init__.py +55 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/client.py +804 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/raw_client.py +1723 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/__init__.py +53 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_create_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_get_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_list_deliveries_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_list_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_replay_event_response.py +30 -0
- blujay-1.0.0/src/blujay/webhook_subscriptions/types/webhook_subscription_update_response.py +30 -0
- blujay-1.0.0/src/blujay/webhooks.py +124 -0
- blujay-1.0.0/src/blujay/workflows/__init__.py +40 -0
- blujay-1.0.0/src/blujay/workflows/client.py +235 -0
- blujay-1.0.0/src/blujay/workflows/raw_client.py +510 -0
- blujay-1.0.0/src/blujay/workflows/types/__init__.py +38 -0
- blujay-1.0.0/src/blujay/workflows/types/workflow_enroll_response.py +30 -0
- blujay-1.0.0/src/blujay/workflows/types/workflow_list_response.py +30 -0
blujay-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this library are listed here. It follows [semantic versioning](https://semver.org).
|
|
4
|
+
|
|
5
|
+
## 1.0.0 (2026-11-10)
|
|
6
|
+
|
|
7
|
+
First release, covering the full Blujay API v1:
|
|
8
|
+
|
|
9
|
+
- Chats: create (with a phone number, or an email address over iMessage), list, read, mark as read, typing indicators; in iMessage groups, rename, group photo, leave and participants
|
|
10
|
+
- Messages: send text, attachments, voice memos, contact cards and links; list, read, edit, unsend, threaded replies, and reactions (tapbacks and emoji)
|
|
11
|
+
- Phone numbers, including Name and Photo Sharing, and iMessage and capability checks
|
|
12
|
+
- Team members you can assign contacts to
|
|
13
|
+
- Contacts (first and last names, and whether someone saved them), notes, tags, assignment, opt-outs and workflows
|
|
14
|
+
- Attachments and vCards
|
|
15
|
+
- Call recordings
|
|
16
|
+
- Webhook subscriptions, deliveries and replays
|
|
17
|
+
- Webhook signature verification (`verify_webhook`), with events typed by `event_type`
|
|
18
|
+
- Request bodies as plain, typed dicts; responses as Pydantic models (1 and 2)
|
|
19
|
+
- Automatic paging, retries for reads, and typed errors with `code`, `trace_id`, `retryable` and `retry_after`
|
blujay-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blujay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
blujay-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: blujay
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python library for the Blujay API: send and receive iMessage, RCS and SMS.
|
|
5
|
+
Project-URL: Homepage, https://docs.blujay.io
|
|
6
|
+
Project-URL: Documentation, https://docs.blujay.io/api-reference
|
|
7
|
+
Project-URL: Repository, https://github.com/blujayhq/blujay-python
|
|
8
|
+
Project-URL: Changelog, https://github.com/blujayhq/blujay-python/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/blujayhq/blujay-python/issues
|
|
10
|
+
Author-email: Blujay <support@blujay.io>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: api,blujay,imessage,messaging,rcs,sms
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Communications
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Requires-Dist: httpx>=0.21.2
|
|
30
|
+
Requires-Dist: pydantic-core>=2.0.0
|
|
31
|
+
Requires-Dist: pydantic>=1.9.2
|
|
32
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
33
|
+
Provides-Extra: aiohttp
|
|
34
|
+
Requires-Dist: aiohttp<4,>=3.10.0; extra == 'aiohttp'
|
|
35
|
+
Requires-Dist: httpx-aiohttp==0.1.8; extra == 'aiohttp'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# Blujay Python Library
|
|
39
|
+
|
|
40
|
+
[](https://pypi.org/project/blujay/)
|
|
41
|
+
[](https://github.com/blujayhq/blujay-python/actions/workflows/ci.yml)
|
|
42
|
+
[](https://github.com/blujayhq/blujay-python/blob/main/LICENSE)
|
|
43
|
+
|
|
44
|
+
The official Python library for the [Blujay API](https://docs.blujay.io). Send and receive iMessage, RCS and SMS from your Blujay phone numbers.
|
|
45
|
+
|
|
46
|
+
- [API docs and guides](https://docs.blujay.io)
|
|
47
|
+
- [Every method in this library](https://github.com/blujayhq/blujay-python/blob/main/reference.md)
|
|
48
|
+
- [Examples](https://github.com/blujayhq/blujay-python/tree/main/examples)
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pip install blujay
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Requires Python 3.9 or later. Works with Pydantic 1 and 2, and ships type hints.
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import os
|
|
62
|
+
|
|
63
|
+
from blujay import Blujay
|
|
64
|
+
|
|
65
|
+
client = Blujay(
|
|
66
|
+
api_key=os.environ["BLUJAY_API_KEY"], # the default, so you can leave it out
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
sent = client.chats.create(
|
|
70
|
+
to=["+15555550123"],
|
|
71
|
+
message={"parts": [{"type": "text", "text": "Hi! Thanks for reaching out."}]},
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
print(sent.data.chat_id, sent.data.message.id)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Have more than one Blujay number? Add `from_="+15555550100"` to choose which one sends. To retry a send safely, see [Retries and idempotency](#retries-and-idempotency).
|
|
78
|
+
|
|
79
|
+
Workspace owners and admins find the API key in Blujay under **API** in the sidebar. Keep it on your server; never ship it to a browser or app.
|
|
80
|
+
|
|
81
|
+
## Async
|
|
82
|
+
|
|
83
|
+
`AsyncBlujay` has the same methods, awaited:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import asyncio
|
|
87
|
+
|
|
88
|
+
from blujay import AsyncBlujay
|
|
89
|
+
|
|
90
|
+
client = AsyncBlujay()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def main() -> None:
|
|
94
|
+
me = await client.me.get()
|
|
95
|
+
print(me.data.workspace_label)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
asyncio.run(main())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Responses
|
|
102
|
+
|
|
103
|
+
Every method that returns JSON gives you the API's response envelope. The result is in `data`, and `trace_id` identifies the request if you contact support:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
chat = client.chats.get(chat_id="chat_abc123")
|
|
107
|
+
print(chat.data.participants, chat.trace_id)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Pass request bodies as plain dicts. They're typed (`message` is a `MessageInputParams`), so your editor and type checker catch a misspelled field. Responses are Pydantic models: objects are named for what they are (`Chat`, `Message`, `Contact`), and each method's response is named for the method, so `client.chats.get` returns a `ChatGetResponse`:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from blujay import ChatGetResponse
|
|
114
|
+
|
|
115
|
+
chat: ChatGetResponse = client.chats.get(chat_id="chat_abc123")
|
|
116
|
+
for person in chat.data.participants:
|
|
117
|
+
print(person.address, person.display_name or "")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Pagination
|
|
121
|
+
|
|
122
|
+
List methods page through results for you:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
for chat in client.chats.list():
|
|
126
|
+
print(chat.chat_id)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Or one page at a time:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
page = client.chats.list(limit=50)
|
|
133
|
+
while page is not None:
|
|
134
|
+
for chat in page.items or []:
|
|
135
|
+
print(chat.chat_id)
|
|
136
|
+
page = page.next_page()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Receiving webhooks
|
|
140
|
+
|
|
141
|
+
Blujay sends replies, delivery updates, reactions and calls to your server as webhooks. `verify_webhook` checks that a request came from Blujay and returns the event, typed by its `event_type`:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from blujay import verify_webhook
|
|
145
|
+
|
|
146
|
+
# raw_body: the request body exactly as received, as bytes or str
|
|
147
|
+
event = verify_webhook(raw_body, request.headers, os.environ["BLUJAY_WEBHOOK_SECRET"])
|
|
148
|
+
|
|
149
|
+
if event.event_type == "message.received":
|
|
150
|
+
print(f"New message in {event.data.chat_id}: {event.data.text or '(no text)'}")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Pass the raw body, not parsed JSON: re-serialized JSON won't match the signature. It raises `WebhookVerificationError` when the signature, the timestamp (more than 5 minutes off) or a header is wrong. An event type added after your version of the library arrives as a `WebhookEnvelope` with `data` as a dict.
|
|
154
|
+
|
|
155
|
+
Getting the raw body:
|
|
156
|
+
|
|
157
|
+
- Flask: `request.get_data()`
|
|
158
|
+
- Django: `request.body`
|
|
159
|
+
- FastAPI and Starlette: `await request.body()`
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import os
|
|
163
|
+
|
|
164
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
165
|
+
|
|
166
|
+
from blujay import WebhookVerificationError, verify_webhook
|
|
167
|
+
|
|
168
|
+
app = FastAPI()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@app.post("/webhooks/blujay")
|
|
172
|
+
async def blujay_webhook(request: Request) -> dict:
|
|
173
|
+
try:
|
|
174
|
+
event = verify_webhook(await request.body(), request.headers, os.environ["BLUJAY_WEBHOOK_SECRET"])
|
|
175
|
+
except WebhookVerificationError:
|
|
176
|
+
raise HTTPException(status_code=400)
|
|
177
|
+
print("Received", event.event_type)
|
|
178
|
+
return {}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
See [webhook_server.py](https://github.com/blujayhq/blujay-python/blob/main/examples/webhook_server.py) for a complete server and the [webhooks guide](https://docs.blujay.io/webhooks/overview) for every event.
|
|
182
|
+
|
|
183
|
+
## Handling errors
|
|
184
|
+
|
|
185
|
+
When the API returns an error, the library raises a subclass of `BlujayError`. Its message is one line, such as `404 NOT_FOUND: Chat not found (trace_id trc_8f2a1c0e4b7d)`:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from blujay import BlujayError, NotFoundError
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
client.chats.get(chat_id="chat_missing")
|
|
192
|
+
except NotFoundError:
|
|
193
|
+
print("No such chat")
|
|
194
|
+
except BlujayError as err:
|
|
195
|
+
# code: what went wrong, such as RATE_LIMIT_EXCEEDED. trace_id: include it when you contact support.
|
|
196
|
+
print(err.status_code, err.code, err.trace_id)
|
|
197
|
+
if err.retryable:
|
|
198
|
+
print(f"Safe to retry in {err.retry_after or 1} seconds")
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
| Status | Error |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| 400 | `BadRequestError` |
|
|
204
|
+
| 401 | `UnauthorizedError`: authentication failed (the API key is missing, invalid, expired or revoked) |
|
|
205
|
+
| 403 | `ForbiddenError` |
|
|
206
|
+
| 404 | `NotFoundError` |
|
|
207
|
+
| 409 | `ConflictError` |
|
|
208
|
+
| 413 | `ContentTooLargeError` |
|
|
209
|
+
| 415 | `UnsupportedMediaTypeError` |
|
|
210
|
+
| 422 | `UnprocessableEntityError` |
|
|
211
|
+
| 429 | `TooManyRequestsError` |
|
|
212
|
+
| 500 | `InternalServerError` |
|
|
213
|
+
| 502 | `BadGatewayError` |
|
|
214
|
+
| 503 | `ServiceUnavailableError` |
|
|
215
|
+
|
|
216
|
+
All of them import from `blujay`. Any other error status raises `BlujayError` itself; check `status_code` and `code`. `doc_url` links to the page that explains the code, and `body` holds the full error response. A missing API key raises `BlujayError` when you create the client. Every error code is explained in the [error reference](https://docs.blujay.io/errors).
|
|
217
|
+
|
|
218
|
+
## Retries and idempotency
|
|
219
|
+
|
|
220
|
+
Reads (`GET`) are retried up to 2 times, with backoff, when the connection fails or after a `408`, `429` or `5xx` response. A `Retry-After` header is respected. The TypeScript library does the same.
|
|
221
|
+
|
|
222
|
+
Writes (`POST`, `PUT`, `PATCH`, `DELETE`), including every send and edit, are never retried automatically: if Blujay accepted a send but the response was lost, a retry would text the person twice. Instead, pass an `idempotency_key` on sends. Retrying with the **same** key is always safe; Blujay returns the original result instead of sending again.
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
# Tie the key to the event, so a retry reuses it.
|
|
226
|
+
key = "order-1042-shipped"
|
|
227
|
+
client.chats.messages.send(chat_id="chat_abc123", message=message, idempotency_key=key)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Change the retry count for reads on the client or per request. Writes ignore it and never retry:
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
client = Blujay(max_retries=0)
|
|
234
|
+
client.chats.list(request_options={"max_retries": 5})
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Timeouts
|
|
238
|
+
|
|
239
|
+
Requests time out after 60 seconds. Change it on the client or per request:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
client = Blujay(timeout=20.0)
|
|
243
|
+
client.chats.list(request_options={"timeout": 5})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Downloads
|
|
247
|
+
|
|
248
|
+
Methods that return a file, such as `client.attachments.download` and `client.calls.download_recording`, stream the body in chunks:
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
with open("call.mp3", "wb") as f:
|
|
252
|
+
for chunk in client.calls.download_recording(call_id="call_abc123"):
|
|
253
|
+
f.write(chunk)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Advanced
|
|
257
|
+
|
|
258
|
+
- **Raw response:** `client.chats.with_raw_response.get(chat_id="chat_abc123")` returns the response with its headers.
|
|
259
|
+
- **Extra headers:** pass `request_options={"additional_headers": {...}}`.
|
|
260
|
+
- **Your own HTTP client:** pass `httpx_client=httpx.Client(...)` to `Blujay`, for proxies or custom transports.
|
|
261
|
+
- **aiohttp:** `pip install "blujay[aiohttp]"` to use aiohttp under `AsyncBlujay`.
|
|
262
|
+
|
|
263
|
+
## Versioning
|
|
264
|
+
|
|
265
|
+
This library follows [semantic versioning](https://semver.org). New endpoints and fields arrive in minor versions; anything that could break your code waits for a major version. See the [changelog](https://github.com/blujayhq/blujay-python/blob/main/CHANGELOG.md).
|
|
266
|
+
|
|
267
|
+
## Support
|
|
268
|
+
|
|
269
|
+
- Questions and bugs: [support@blujay.io](mailto:support@blujay.io) or [open an issue](https://github.com/blujayhq/blujay-python/issues)
|
|
270
|
+
- Security issues: see [SECURITY.md](https://github.com/blujayhq/blujay-python/blob/main/SECURITY.md)
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
[MIT](https://github.com/blujayhq/blujay-python/blob/main/LICENSE)
|
blujay-1.0.0/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Blujay Python Library
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/blujay/)
|
|
4
|
+
[](https://github.com/blujayhq/blujay-python/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/blujayhq/blujay-python/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
The official Python library for the [Blujay API](https://docs.blujay.io). Send and receive iMessage, RCS and SMS from your Blujay phone numbers.
|
|
8
|
+
|
|
9
|
+
- [API docs and guides](https://docs.blujay.io)
|
|
10
|
+
- [Every method in this library](https://github.com/blujayhq/blujay-python/blob/main/reference.md)
|
|
11
|
+
- [Examples](https://github.com/blujayhq/blujay-python/tree/main/examples)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pip install blujay
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Python 3.9 or later. Works with Pydantic 1 and 2, and ships type hints.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
from blujay import Blujay
|
|
27
|
+
|
|
28
|
+
client = Blujay(
|
|
29
|
+
api_key=os.environ["BLUJAY_API_KEY"], # the default, so you can leave it out
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
sent = client.chats.create(
|
|
33
|
+
to=["+15555550123"],
|
|
34
|
+
message={"parts": [{"type": "text", "text": "Hi! Thanks for reaching out."}]},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
print(sent.data.chat_id, sent.data.message.id)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Have more than one Blujay number? Add `from_="+15555550100"` to choose which one sends. To retry a send safely, see [Retries and idempotency](#retries-and-idempotency).
|
|
41
|
+
|
|
42
|
+
Workspace owners and admins find the API key in Blujay under **API** in the sidebar. Keep it on your server; never ship it to a browser or app.
|
|
43
|
+
|
|
44
|
+
## Async
|
|
45
|
+
|
|
46
|
+
`AsyncBlujay` has the same methods, awaited:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import asyncio
|
|
50
|
+
|
|
51
|
+
from blujay import AsyncBlujay
|
|
52
|
+
|
|
53
|
+
client = AsyncBlujay()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def main() -> None:
|
|
57
|
+
me = await client.me.get()
|
|
58
|
+
print(me.data.workspace_label)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
asyncio.run(main())
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Responses
|
|
65
|
+
|
|
66
|
+
Every method that returns JSON gives you the API's response envelope. The result is in `data`, and `trace_id` identifies the request if you contact support:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
chat = client.chats.get(chat_id="chat_abc123")
|
|
70
|
+
print(chat.data.participants, chat.trace_id)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Pass request bodies as plain dicts. They're typed (`message` is a `MessageInputParams`), so your editor and type checker catch a misspelled field. Responses are Pydantic models: objects are named for what they are (`Chat`, `Message`, `Contact`), and each method's response is named for the method, so `client.chats.get` returns a `ChatGetResponse`:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from blujay import ChatGetResponse
|
|
77
|
+
|
|
78
|
+
chat: ChatGetResponse = client.chats.get(chat_id="chat_abc123")
|
|
79
|
+
for person in chat.data.participants:
|
|
80
|
+
print(person.address, person.display_name or "")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Pagination
|
|
84
|
+
|
|
85
|
+
List methods page through results for you:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
for chat in client.chats.list():
|
|
89
|
+
print(chat.chat_id)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Or one page at a time:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
page = client.chats.list(limit=50)
|
|
96
|
+
while page is not None:
|
|
97
|
+
for chat in page.items or []:
|
|
98
|
+
print(chat.chat_id)
|
|
99
|
+
page = page.next_page()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Receiving webhooks
|
|
103
|
+
|
|
104
|
+
Blujay sends replies, delivery updates, reactions and calls to your server as webhooks. `verify_webhook` checks that a request came from Blujay and returns the event, typed by its `event_type`:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from blujay import verify_webhook
|
|
108
|
+
|
|
109
|
+
# raw_body: the request body exactly as received, as bytes or str
|
|
110
|
+
event = verify_webhook(raw_body, request.headers, os.environ["BLUJAY_WEBHOOK_SECRET"])
|
|
111
|
+
|
|
112
|
+
if event.event_type == "message.received":
|
|
113
|
+
print(f"New message in {event.data.chat_id}: {event.data.text or '(no text)'}")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Pass the raw body, not parsed JSON: re-serialized JSON won't match the signature. It raises `WebhookVerificationError` when the signature, the timestamp (more than 5 minutes off) or a header is wrong. An event type added after your version of the library arrives as a `WebhookEnvelope` with `data` as a dict.
|
|
117
|
+
|
|
118
|
+
Getting the raw body:
|
|
119
|
+
|
|
120
|
+
- Flask: `request.get_data()`
|
|
121
|
+
- Django: `request.body`
|
|
122
|
+
- FastAPI and Starlette: `await request.body()`
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import os
|
|
126
|
+
|
|
127
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
128
|
+
|
|
129
|
+
from blujay import WebhookVerificationError, verify_webhook
|
|
130
|
+
|
|
131
|
+
app = FastAPI()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@app.post("/webhooks/blujay")
|
|
135
|
+
async def blujay_webhook(request: Request) -> dict:
|
|
136
|
+
try:
|
|
137
|
+
event = verify_webhook(await request.body(), request.headers, os.environ["BLUJAY_WEBHOOK_SECRET"])
|
|
138
|
+
except WebhookVerificationError:
|
|
139
|
+
raise HTTPException(status_code=400)
|
|
140
|
+
print("Received", event.event_type)
|
|
141
|
+
return {}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See [webhook_server.py](https://github.com/blujayhq/blujay-python/blob/main/examples/webhook_server.py) for a complete server and the [webhooks guide](https://docs.blujay.io/webhooks/overview) for every event.
|
|
145
|
+
|
|
146
|
+
## Handling errors
|
|
147
|
+
|
|
148
|
+
When the API returns an error, the library raises a subclass of `BlujayError`. Its message is one line, such as `404 NOT_FOUND: Chat not found (trace_id trc_8f2a1c0e4b7d)`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from blujay import BlujayError, NotFoundError
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
client.chats.get(chat_id="chat_missing")
|
|
155
|
+
except NotFoundError:
|
|
156
|
+
print("No such chat")
|
|
157
|
+
except BlujayError as err:
|
|
158
|
+
# code: what went wrong, such as RATE_LIMIT_EXCEEDED. trace_id: include it when you contact support.
|
|
159
|
+
print(err.status_code, err.code, err.trace_id)
|
|
160
|
+
if err.retryable:
|
|
161
|
+
print(f"Safe to retry in {err.retry_after or 1} seconds")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
| Status | Error |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| 400 | `BadRequestError` |
|
|
167
|
+
| 401 | `UnauthorizedError`: authentication failed (the API key is missing, invalid, expired or revoked) |
|
|
168
|
+
| 403 | `ForbiddenError` |
|
|
169
|
+
| 404 | `NotFoundError` |
|
|
170
|
+
| 409 | `ConflictError` |
|
|
171
|
+
| 413 | `ContentTooLargeError` |
|
|
172
|
+
| 415 | `UnsupportedMediaTypeError` |
|
|
173
|
+
| 422 | `UnprocessableEntityError` |
|
|
174
|
+
| 429 | `TooManyRequestsError` |
|
|
175
|
+
| 500 | `InternalServerError` |
|
|
176
|
+
| 502 | `BadGatewayError` |
|
|
177
|
+
| 503 | `ServiceUnavailableError` |
|
|
178
|
+
|
|
179
|
+
All of them import from `blujay`. Any other error status raises `BlujayError` itself; check `status_code` and `code`. `doc_url` links to the page that explains the code, and `body` holds the full error response. A missing API key raises `BlujayError` when you create the client. Every error code is explained in the [error reference](https://docs.blujay.io/errors).
|
|
180
|
+
|
|
181
|
+
## Retries and idempotency
|
|
182
|
+
|
|
183
|
+
Reads (`GET`) are retried up to 2 times, with backoff, when the connection fails or after a `408`, `429` or `5xx` response. A `Retry-After` header is respected. The TypeScript library does the same.
|
|
184
|
+
|
|
185
|
+
Writes (`POST`, `PUT`, `PATCH`, `DELETE`), including every send and edit, are never retried automatically: if Blujay accepted a send but the response was lost, a retry would text the person twice. Instead, pass an `idempotency_key` on sends. Retrying with the **same** key is always safe; Blujay returns the original result instead of sending again.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# Tie the key to the event, so a retry reuses it.
|
|
189
|
+
key = "order-1042-shipped"
|
|
190
|
+
client.chats.messages.send(chat_id="chat_abc123", message=message, idempotency_key=key)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Change the retry count for reads on the client or per request. Writes ignore it and never retry:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
client = Blujay(max_retries=0)
|
|
197
|
+
client.chats.list(request_options={"max_retries": 5})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Timeouts
|
|
201
|
+
|
|
202
|
+
Requests time out after 60 seconds. Change it on the client or per request:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
client = Blujay(timeout=20.0)
|
|
206
|
+
client.chats.list(request_options={"timeout": 5})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Downloads
|
|
210
|
+
|
|
211
|
+
Methods that return a file, such as `client.attachments.download` and `client.calls.download_recording`, stream the body in chunks:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
with open("call.mp3", "wb") as f:
|
|
215
|
+
for chunk in client.calls.download_recording(call_id="call_abc123"):
|
|
216
|
+
f.write(chunk)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Advanced
|
|
220
|
+
|
|
221
|
+
- **Raw response:** `client.chats.with_raw_response.get(chat_id="chat_abc123")` returns the response with its headers.
|
|
222
|
+
- **Extra headers:** pass `request_options={"additional_headers": {...}}`.
|
|
223
|
+
- **Your own HTTP client:** pass `httpx_client=httpx.Client(...)` to `Blujay`, for proxies or custom transports.
|
|
224
|
+
- **aiohttp:** `pip install "blujay[aiohttp]"` to use aiohttp under `AsyncBlujay`.
|
|
225
|
+
|
|
226
|
+
## Versioning
|
|
227
|
+
|
|
228
|
+
This library follows [semantic versioning](https://semver.org). New endpoints and fields arrive in minor versions; anything that could break your code waits for a major version. See the [changelog](https://github.com/blujayhq/blujay-python/blob/main/CHANGELOG.md).
|
|
229
|
+
|
|
230
|
+
## Support
|
|
231
|
+
|
|
232
|
+
- Questions and bugs: [support@blujay.io](mailto:support@blujay.io) or [open an issue](https://github.com/blujayhq/blujay-python/issues)
|
|
233
|
+
- Security issues: see [SECURITY.md](https://github.com/blujayhq/blujay-python/blob/main/SECURITY.md)
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
[MIT](https://github.com/blujayhq/blujay-python/blob/main/LICENSE)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
| File | What it shows |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| [send_message.py](send_message.py) | Text someone, then read the message's status |
|
|
6
|
+
| [webhook_server.py](webhook_server.py) | Receive webhooks, verify the signature, handle new messages |
|
|
7
|
+
|
|
8
|
+
Run them from an environment that has `blujay` installed. Guides for every feature are at [docs.blujay.io](https://docs.blujay.io).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Text someone from your Blujay number, then check how the message is doing.
|
|
2
|
+
|
|
3
|
+
BLUJAY_API_KEY=blu_... python examples/send_message.py +15555550123
|
|
4
|
+
"""
|
|
5
|
+
import sys
|
|
6
|
+
import uuid
|
|
7
|
+
|
|
8
|
+
from blujay import Blujay, BlujayError
|
|
9
|
+
|
|
10
|
+
if len(sys.argv) < 2:
|
|
11
|
+
sys.exit("Pass the phone number to text, for example +15555550123")
|
|
12
|
+
to = sys.argv[1]
|
|
13
|
+
|
|
14
|
+
# Reads BLUJAY_API_KEY from the environment.
|
|
15
|
+
client = Blujay()
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
# Starts a chat with this person, or reuses the one you already have.
|
|
19
|
+
# Keep the idempotency key with your record of this send: retrying with the
|
|
20
|
+
# same key can't send the message twice.
|
|
21
|
+
sent = client.chats.create(
|
|
22
|
+
to=[to],
|
|
23
|
+
message={"parts": [{"type": "text", "text": "Hi! Thanks for reaching out."}]},
|
|
24
|
+
idempotency_key=str(uuid.uuid4()),
|
|
25
|
+
)
|
|
26
|
+
print(f"Sent {sent.data.message.id} in chat {sent.data.chat_id}")
|
|
27
|
+
|
|
28
|
+
# Messages go out in the background. Webhooks tell you when the status
|
|
29
|
+
# changes; you can also read it at any time.
|
|
30
|
+
message = client.messages.get(message_id=sent.data.message.id)
|
|
31
|
+
print(f"Status: {message.data.status}, service: {message.data.service or 'not chosen yet'}")
|
|
32
|
+
except BlujayError as err:
|
|
33
|
+
# One line with the status, the error code you can act on and the trace ID for support.
|
|
34
|
+
sys.exit(str(err))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Receive Blujay webhooks: verify each request, then handle the event.
|
|
2
|
+
|
|
3
|
+
BLUJAY_WEBHOOK_SECRET=whsec_... python examples/webhook_server.py
|
|
4
|
+
|
|
5
|
+
Point a webhook subscription at http://your-server:3000/webhooks/blujay.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
9
|
+
|
|
10
|
+
from blujay import WebhookVerificationError, verify_webhook
|
|
11
|
+
|
|
12
|
+
SECRET = os.environ.get("BLUJAY_WEBHOOK_SECRET", "")
|
|
13
|
+
if not SECRET:
|
|
14
|
+
raise SystemExit("Set BLUJAY_WEBHOOK_SECRET to your subscription's signing secret")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Handler(BaseHTTPRequestHandler):
|
|
18
|
+
def do_POST(self):
|
|
19
|
+
if self.path != "/webhooks/blujay":
|
|
20
|
+
self.send_response(404)
|
|
21
|
+
self.end_headers()
|
|
22
|
+
return
|
|
23
|
+
# Verify the raw body exactly as it arrived; parsed and re-serialized JSON won't match.
|
|
24
|
+
body = self.rfile.read(int(self.headers.get("content-length", 0)))
|
|
25
|
+
try:
|
|
26
|
+
event = verify_webhook(body, self.headers, SECRET)
|
|
27
|
+
except WebhookVerificationError as err:
|
|
28
|
+
self.send_response(400)
|
|
29
|
+
self.end_headers()
|
|
30
|
+
self.wfile.write(str(err).encode())
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
# Blujay can deliver an event more than once: skip event IDs you've already handled.
|
|
34
|
+
# `event` is typed by event_type, so each branch knows the shape of `data`.
|
|
35
|
+
if event.event_type == "message.received":
|
|
36
|
+
sender = event.data.sender.address if event.data.sender else event.data.contact_id
|
|
37
|
+
attachments = [part for part in event.data.parts or [] if part.type == "media"]
|
|
38
|
+
print(f"New message from {sender} in {event.data.chat_id}: {event.data.text or '(no text)'}")
|
|
39
|
+
if attachments:
|
|
40
|
+
print(f" with {len(attachments)} attachment(s)")
|
|
41
|
+
elif event.event_type == "message.delivered":
|
|
42
|
+
print(f"Delivered {event.data.message_id} by {event.data.service or 'unknown service'}")
|
|
43
|
+
elif event.event_type == "message.failed":
|
|
44
|
+
print(f"Failed {event.data.message_id}: {event.data.failure.reason if event.data.failure else 'no reason given'}")
|
|
45
|
+
else:
|
|
46
|
+
print(f"Received {event.event_type}")
|
|
47
|
+
# Answer quickly; do slow work after responding.
|
|
48
|
+
self.send_response(200)
|
|
49
|
+
self.end_headers()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
print("Listening on http://localhost:3000/webhooks/blujay")
|
|
53
|
+
HTTPServer(("", 3000), Handler).serve_forever()
|