How to use the messagebird.client function in messagebird

To help you get started, we’ve selected a few messagebird examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github messagebird / python-rest-api / examples / conversation_create_webhook.py View on Github external
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    webhook = client.conversation_create_webhook({
        'channelId': args['channelId'],
        'events': [CONVERSATION_WEBHOOK_EVENT_CONVERSATION_CREATED, CONVERSATION_WEBHOOK_EVENT_CONVERSATION_UPDATED],
        'url': args['url']
    })

    # Print the object information.
    print('The following information was returned as a Webhook object:')
    print(webhook)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Webhook object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / conversation_update.py View on Github external
parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--conversationId', help='conversation ID that you want to update', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    conversation = client.conversation_update(args['conversationId'], {'status': 'active'})

    # Print the object information.
    print('The following information was returned as a Conversation object:')
    print(conversation)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Conversation object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / lookup.py View on Github external
print('  countryPrefix         : %d' % lookup.countryPrefix)
  print('  type                  : %s' % lookup.type)
  print('  formats.e164          : %s' % lookup.formats.e164)
  print('  formats.international : %s' % lookup.formats.international)
  print('  formats.national      : %s' % lookup.formats.national)
  print('  formats.rfc3966       : %s' % lookup.formats.rfc3966)

  if lookup.hlr is not None:
    print('  hlr.id                : %s' % lookup.hlr.id)
    print('  hlr.network           : %d' % lookup.hlr.network)
    print('  hlr.reference         : %s' % lookup.hlr.reference)
    print('  hlr.status            : %s' % lookup.hlr.status)
    print('  hlr.createdDatetime   : %s' % lookup.hlr.createdDatetime)
    print('  hlr.statusDatetime    : %s' % lookup.hlr.statusDatetime)

except messagebird.client.ErrorException as e:
  print('\nAn error occured while requesting a Lookup object:\n')

  for error in e.errors:
    print('  code        : %d' % error.code)
    print('  description : %s' % error.description)
    print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / voice_delete_webhook.py View on Github external
import messagebird

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True)

args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])
    webhook = client.voice_delete_webhook(args['webhookId'])

    # Print the object information.
    print('Webhook has been deleted')

except messagebird.client.ErrorException as e:
    print('An error occured while deleting a Voice Webhook object:')

    for error in e.errors:
        print('  code        : {}'.format(error.code))
        print('  description : {}'.format(error.description))
        print('  parameter   : {}\n'.format(error.parameter))
github messagebird / python-rest-api / examples / number_update.py View on Github external
# Note: at the moment, we only support updating tags that can be used to group or label numbers
    tags = ['tag1']
    number = client.update_number('3197010240126', tags)

    # Print the object information.
    print('\nThe following information was returned as a Number object:\n')
    print('    number                : %s' % number.number)
    print('    country               : %s' % number.country)
    print('    region                : %s' % number.region)
    print('    locality              : %s' % number.locality)
    print('    features              : %s' % number.features)
    print('    tags                  : %s' % number.tags)
    print('    type                  : %s' % number.type)
    print('    status                : %s' % number.status)

except messagebird.client.ErrorException as e:
    print('\nAn error occured while requesting a NumberList object:\n')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)

except requests.exceptions.HTTPError as e:
    print('\nAn HTTP exception occurred while fetching all purchased phone numbers:')
    print(' ', e)
    print('  Http request body: ', e.request.body)
    print('  Http response status: ', e.response.status_code)
    print('  Http response body: ', e.response.content.decode())

except Exception as e:
    print('\nAn ', e.__class__, ' exception occurred while :')
github messagebird / python-rest-api / examples / conversation_read_webhook.py View on Github external
parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--webhookId', help='webhook that you want to read', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    webhook = client.conversation_read_webhook(args['webhookId'])

    # Print the object information.
    print('The following information was returned as a Webhook object:')
    print(webhook)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Webhook object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / conversation_delete_webhook.py View on Github external
import messagebird

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
parser.add_argument('--webhookId', help='webhook that you want to delete', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    client.conversation_delete_webhook(args['webhookId'])

    # Print the object information.
    print('Webhook has been deleted')

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Webhook object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / number_purchased_list.py View on Github external
print('  Containing the the following items:')
        for item in numbers.items:
            print('  {')
            print('    number                : %s' % item.number)
            print('    country               : %s' % item.country)
            print('    region                : %s' % item.region)
            print('    locality              : %s' % item.locality)
            print('    features              : %s' % item.features)
            print('    tags                  : %s' % item.tags)
            print('    type                  : %s' % item.type)
            print('    status                : %s' % item.status)
            print('  },')
        else:
            print('  With an empty response.')

except messagebird.client.ErrorException as e:
    print('\nAn error occurred while fetching all purchased phone numbers:\n')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s' % error.parameter)
        print('  type        : %s' % error.__class__)

except requests.exceptions.HTTPError as e:
    print('\nAn HTTP exception occurred while fetching all purchased phone numbers:')
    print(' ', e)
    print('  Http request body: ', e.request.body)
    print('  Http response status: ', e.response.status_code)
    print('  Http response body: ', e.response.content.decode())

except Exception as e:
github messagebird / python-rest-api / examples / voice_message_create.py View on Github external
# Print the object information.
  print('\nThe following information was returned as a VoiceMessage object:\n')
  print('  id                : %s' % vmsg.id)
  print('  href              : %s' % vmsg.href)
  print('  originator        : %s' % vmsg.originator)
  print('  body              : %s' % vmsg.body)
  print('  reference         : %s' % vmsg.reference)
  print('  language          : %s' % vmsg.language)
  print('  voice             : %s' % vmsg.voice)
  print('  repeat            : %s' % vmsg.repeat)
  print('  ifMachine         : %s' % vmsg.ifMachine)
  print('  scheduledDatetime : %s' % vmsg.scheduledDatetime)
  print('  createdDatetime   : %s' % vmsg.createdDatetime)
  print('  recipients        : %s\n' % vmsg.recipients)

except messagebird.client.ErrorException as e:
  print('\nAn error occured while requesting a VoiceMessage object:\n')

  for error in e.errors:
    print('  code        : %d' % error.code)
    print('  description : %s' % error.description)
    print('  parameter   : %s\n' % error.parameter)
github messagebird / python-rest-api / examples / conversation_list.py View on Github external
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
args = vars(parser.parse_args())

try:
    client = messagebird.Client(args['accessKey'])

    conversationList = client.conversation_list()

    # Print the object information.
    print('The following information was returned as a Conversation List object:')
    print(conversationList)

except messagebird.client.ErrorException as e:
    print('An error occured while requesting a Message object:')

    for error in e.errors:
        print('  code        : %d' % error.code)
        print('  description : %s' % error.description)
        print('  parameter   : %s\n' % error.parameter)