GithubHelp home page GithubHelp logo

messagebird / python-rest-api Goto Github PK

View Code? Open in Web Editor NEW
64.0 64.0 66.0 290 KB

This repository contains the open source Python client for MessageBird's REST API.

License: BSD 2-Clause "Simplified" License

Python 100.00%
messagebird python sms

python-rest-api's People

Contributors

17twentynine avatar aleixdev avatar donis avatar dysosmus avatar epels avatar guiajlopes avatar jornengelbart avatar kcroxford-mb avatar marcelcorso avatar mariuspot avatar max-inanc avatar michi88 avatar nqkdev avatar prep avatar rfeiner avatar rjelierse avatar roaldnefs avatar samwierema avatar sarathsp06 avatar sbogx avatar sebastiaanmb avatar stefan-messagebird avatar surik avatar valenmope avatar victormb84 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  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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

python-rest-api's Issues

When sending voice messages with test credits the order of the recipients may throw an error

How to reproduce?

  • create a new messagebird account with and claim test credits using the phone number +3131611111111.
  • try to send a voice message to multiple recipients but use another phone number (say +3131622222222) as the first of the list. Like this:
ACCESS_KEY = 'live_333aacc22bbbddd'
client = messagebird.Client(ACCESS_KEY)
vmsg = client.voice_message_create('3131611111111, 3131622222222', 'Hello friend.', { 'reference' : 'Foobar' })

The message gets send to the number 3131611111111 but the call raises this exception:

Traceback (most recent call last):
  File "voice_message_create.py", line 15, in <module>
    vmsg = client.voice_message_create('31630174123, 31624971134', 'Hello sugar.', { 'reference' : 'Foobar' })
  File "../messagebird/client.py", line 94, in voice_message_create
    return VoiceMessage().load(self.request('voicemessages', 'POST', params))
  File "../messagebird/base.py", line 7, in load
    setattr(self, name, value)
  File "../messagebird/voicemessage.py", line 41, in recipients
    value['items'] = [Recipient().load(r) for r in value['items']]
  File "../messagebird/base.py", line 5, in load
    for name, value in data.items():
AttributeError: 'unicode' object has no attribute 'items'

If you change the order of the recipients to '3131622222222, 3131611111111' it works.

This exception shouldn't be risen.

Wrong message id on client.conversation_start for WhatsApp

I'm getting wrong message_id on client.conversation_start
message id is different from the server.
each time client.conversation_start returns same id

def conversation_start(self, start_request):
uri = CONVERSATION_PATH + '/start'
return Conversation().load(self.request(uri, 'POST', start_request, CONVERSATION_TYPE))

on the conversations history all ids are different.
Can somebody please fix this ?

issue in MessageBird WhatsApp Python SDK

There is an Error

  code        : 21
  description : Channel not found
  parameter   : channelId

When I trying to send a message to WhatsApp (template), I'm using Live API Key and Correct Channel ID.
Note: I'm able to send message using cURL with normal text. there is no such error for Channel ID.

ConversationMessage empty with whatsapp sandbox

The response from the whatsapp sandbox when creating a message has variable names with different capitalization than the ConversationMessage object, meaning that the conversation message objects that are returned from client.conversation_read_message and client.conversation_create_message are empty.

Sort contacts by createdDatetime

Hi

Is there a query argument for the /contacts/ endpoint to sort the contacts ascending or descending by createdDatetime?

Thanks,

pipenv

pyenv install 3.4.10
pipenv install --python 3.4.10
pipenv install messagebird
pipenv run python examples/number_available_list.py --accessKey XXXXXXXXXXXXXXX

An  <class 'AttributeError'>  exception occurred while :
'Client' object has no attribute 'available_numbers_list'

Python SDK Issue

image

Getting an error above when using SDK's conversation_start with paid channel.

But no issue with the same SDK method to send out template messages with sandbox channel

AttributeError 'str' object has no attribute 'items'

Hi,

I'm intermittently getting the following error when sending SMS messages using the Python client:

https://app.getsentry.com/share/issue/38393239372e313531303139363139/

The reason for the error appears to be the format the Python code expects back at this point (https://app.getsentry.com/share/issue/38393239372e313531303139363139/):

@recipients.setter
  def recipients(self, value):
    value['items'] = [Recipient().load(r) for r in value['items']]
    self._recipients = value

which differs from what the API returns (I've removed the real number but will happily share privately if that helps):

{
    'items': {
        '1': {
            'recipient': xxxxxxxxxx, 
            'status': 'sent', 
            'statusDatetime': '2016-08-18T21:26:06+00:00'
        }
    }, 
    'totalCount': 1, 
    'totalDeliveredCount': 0, 
    'totalDeliveryFailedCount': 0, 
    'totalSentCount': 1
}

So basically this line appears to expect a list of dictionaries back...

value['items'] = [Recipient().load(r) for r in value['items']]

... but it's getting a dictionary or dictionaries with the key 1, and the list comprehension here is simply sending through the key which isn't the dictionary expected by load(r).

Since this doesn't always happen this seems most likely to be an error with the API, as in I can't see anywhere in the code where it would handle data in this structure received back from the API and for the most part this error doesn't occur when I send text messages. Also the API docs and example suggest items should be a list not a dictionary (https://developers.messagebird.com/docs/messaging#messaging-send).

A possible short-term hack I could try would be to patch the library to sniff the data type first, e.g:

@recipients.setter
  def recipients(self, value):
    if isinstance(value['items'], dict):
        items = value['items']
        keys = sorted([int(k) for k in items.keys()])
        value['items'] = [Recipient().load(items[k]) for k in keys]
    else:
        value['items'] = [Recipient().load(r) for r in value['items']]
    self._recipients = value

...though if I'm honest I'd really prefer not to have to do this.

I'm using version 1.2.0 of your Python client library.

AttributeError: partially initialized module 'messagebird' has no attribute 'Client' (most likely due to a circular import)

After pip install, import and initializing the client

Traceback (most recent call last):
  File "messagebird.py", line 1, in <module>
    import messagebird
  File "/home/carlos/Escritorio/projects/twilio/messagebird.py", line 2, in <module>
    client = messagebird.Client('YOUR_ACCESS_KEY')
AttributeError: partially initialized module 'messagebird' has no attribute 'Client' (most likely due to a circular import)

Thank you

Lookup method can raise HTTP 400 with errors body

When looking up a phone number to do preliminary validation, the API can raise a HTTPError instead of ErrorException, as the HTTP status code 400 is not handled in the client.

Raising an ErrorException would be more consistent, as a HTTPError usually indicates networking errors or bad requests, not "phone number seems invalid".

Sample response:

x
Out[91]: requests.exceptions.HTTPError('400 Client Error: Bad Request for url: https://rest.messagebird.com/lookup/1234567890')

x.response.content
Out[92]: b'{"errors":[{"code":21,"description":"Bad request (phone number has unknown format)","parameter":"phone_number"}]}\n'```

pip update

It seems like your pip version is not updated.
Calling >>>pip install messagebird installs package version 1.4.1. This is how messagebird/client.py looks like:

class Client(object):
def init(self, access_key, http_client=None):

This is version on git:

class Client(object):
def init(self, access_key, http_client=None, features=[]):

Unclear tutorial Python SMS

Dear reader,

I'm trying to implement your awesome SMS API into my Python final assignmetn (for higher education semester 1). The deadline is two weeks from now and I've been busy for 2 weeks..

The following guide:
https://developers.messagebird.com/quickstarts/sms/send-sms-python

  • pip install messagebird was succesfull
    But after that you ask to place an recipient and originator.

By copy/pasting your tutorial code and insert my own phone number, I still don't get the program to run. I've managed to do it in Node.JS and those instructions were clear. I ask if you please create the SMS feature locally in Python by following exactly the tutorial please.

Does that work for you then?
I have tried your template and then tried editing to:
import messagebird

client = messagebird.Client('ypt3ryCKm0WnfppAQt3hcd0Yt')
message = client.message_create(
'+31610433256',
{'originator': '+31610433256'},
{'recepient': '+31610433256'},
'Hello World, mijn eerste SMS',
{ 'reference' : 'Foobar' }
)

But I receive in both cases:
code:
send_sms.py : The term 'send_sms.py' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • send_sms.py
  • CategoryInfo : ObjectNotFound: (send_sms.py:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException

Can you please help me?
Kind regards,
Leroy Andrade

Reporting a vulnerability

Hello!

I hope you are doing well!

We are a security research team. Our tool automatically detected a vulnerability in this repository. We want to disclose it responsibly. GitHub has a feature called Private vulnerability reporting, which enables security research to privately disclose a vulnerability. Unfortunately, it is not enabled for this repository.

Can you enable it, so that we can report it?

Thanks in advance!

PS: you can read about how to enable private vulnerability reporting here: https://docs.github.com/en/code-security/security-advisories/repository-security-advisories/configuring-private-vulnerability-reporting-for-a-repository

Python example/balance.py does not 'compile'

Running API via python does not work:

[rvdzwet@rvdzwet-asus python-rest-api]$ python examples/balance.py

An error occured while requesting a Balance object:

  code        : 2
  description : Request not allowed (incorrect access_key)
  parameter   : access_key

Fixed curl request (with same dummy key) goes just fine:

[rvdzwet@rvdzwet-asus ~]$ curl  https://rest.messagebird.com/balance -H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'
{"payment":"prepaid","type":"credits","amount":10.1}

Not able to send message from python file

I am following this process using messagebird library.
I am combining message_create.py and message.py.

client = messagebird.Client(ACCESS_KEY)
msg = client.message_create(originator_phonenumber, array of recipient_phonenumber, 'Hello World')
ms = client.message(msg.id)

and I am getting this error:
An error occured while requesting a Message object:
code : 20
description : message not found
parameter : None

@samwierema Please help me on this.

No client method for /v1/send handler

Hey,

As far as I can see, the Send Message handler, i.e. POST to /v1/send , has no equivalents in this Python library, is this correct?

I do see that #75 implements it -- specifically here.

This is my vote for a merge on that PR :-) Let me know if I can help resolve the merge conflict.

Thanks!

Arabic Text Body issue

hello, i am currently facing an issue when trying to send messages in arabic with the message bird api. it works perfectly fine with other languages but not arabic.
here's a code snippet:
`

import messagebird
import arabic_reshaper
def send_msg(receiver, expiration_date):
if receiver == NULL:
pass
else:
expiration_date = expiration_date[::-1]
text = f"عزيزي العميل ، ينتهي اشتراكك في XXX غدًا بتاريخ {expiration_date}، لتجديده ، يرجى الاتصال بنا."
reshaped_text = arabic_reshaper.reshape(text)
rev_text = reshaped_text[::-1]
client = messagebird.Client("XXXXXXXXX")
message = client.message_create('XXXXXTest',
f'{str(receiver)}',
rev_text,
{ 'reference' : 'Foobar' }
)
`
i tried using arabic reshaper module and when i print the "rev_text" in the terminal it works perfectly fine, meaning that it is shown the way it is expected
but when i receive the message on my phone, there are no arabic characters what so ever, as if they were deleted entirely, meaning i only receive the expiration date and the "XXX" and nothing else. please view the image below to understand what i mean.

attatchment

Link to documentation in README.md is out of date

The README.md file says, at the end:

Complete documentation, instructions, and examples are available at: https://www.messagebird.com/developers/python.

However, this link redirects to the generic https://developers.messagebird.com/ page, which is not Python-specific.

Either the link should be updated to point to Python-specific documentation, or it should point to the generic page (so that users aren't confused/frustrated at getting a generic page when they've been led to expect a Python-specific one).

Issue for Response in MessageBird WhatsApp Python SDK

There is an error when sending a message through Whatsapp. The message comes through and is received on the app, but the response json for

client.conversation_start({ })

instead of it being an error or success is the following.

File "/usr/local/lib/python3.8/site-packages/messagebird/client.py", line 343, in conversation_start return Conversation().load(self.request(uri, 'POST', start_request, CONVERSATION_TYPE)) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 11, in load setattr(self, name, value) File "/usr/local/lib/python3.8/site-packages/messagebird/conversation.py", line 30, in contact self._contact = ConversationContact().load(value) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 11, in load setattr(self, name, value) File "/usr/local/lib/python3.8/site-packages/messagebird/conversation_contact.py", line 23, in customDetails self._customDetails = CustomDetails().load(value) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 9, in load for name, value in list(data.items()):

Channel id, namespace and test phone number as omitted for security but are all correct. The code being is used is:
msg = client.conversation_start({ 'channelId': '####', 'to': '521##########', 'type': MESSAGE_TYPE_HSM, 'content': { 'hsm': { 'namespace': '####', 'templateName': 'verification', 'language': { 'policy': 'deterministic', 'code': 'en' }, 'params': [ {"default": "MessageBird"}, {"default": "123456"} ] } } })

Voice Messaging: handling machine answers

Hi,
I'm trying to implement some text to speech voice message.

I need to detect machine answers to be able to call another phone for notification escalation.

But get status like these with ifMachine set to 'hangup':

calling calling calling ... answered

Second try, I hang up the call manually:

calling calling calling ... answered

So, is there a way to detect both these two scenarios (machine answer and manual hang up) ?

jfr

MessageBird: [Version 2.0.0]

Waiting for new release on pip

I see that you have implemented RequestValidator but it's not released yet.

Since, I (and many others) add packages via pip, the latest version we have is v2.0.0. Using that version, I can't migrate request validation from MessageBird-Signature and MessageBird-Request-Timestamp to MessageBird-Signature-JWT header.

Thanks.

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.