examples/pyramidWebexTeamsBot/pyramidWebexTeamsBot/views.py
def post_events_service(request):
    """Respond to inbound webhook JSON HTTP POST from Webex Teams."""

    # Get the POST data sent from Webex Teams
    json_data = request.json
    log.info("\n")
    log.info("WEBHOOK POST RECEIVED:")
    log.info(json_data)
    log.info("\n")

    # Create a Webhook object from the JSON data
    webhook_obj = Webhook(json_data)

    # Get the room details
    room = api.rooms.get(webhook_obj.data.roomId)

    # Get the message details
    message = api.messages.get(webhook_obj.data.id)

    # Get the sender's details
    person = api.people.get(message.personId)

    log.info("NEW MESSAGE IN ROOM '{}'".format(room.title))
    log.info("FROM '{}'".format(person.displayName))
    log.info("MESSAGE '{}'\n".format(message.text))

    # This is a VERY IMPORTANT loop prevention control step.
    # If you respond to all messages...  You will respond to the messages
    # that the bot posts and thereby create a loop condition.
    me = api.people.me()
    if message.personId == me.id:
        # Message was sent by me (bot); do not respond.
        return {'Message': 'OK'}

    else:
        # Message was sent by someone else; parse message and respond.
        if "/CAT" in message.text:
            log.info("FOUND '/CAT'")

            # Get a cat fact
            catfact = get_catfact()
            log.info("SENDING CAT FACT'{}'".format(catfact))

            # Post the fact to the room where the request was received
            api.messages.create(room.id, text=catfact)
        return {'Message': 'OK'}
def post_events_service(request):
    # Get the POST data sent from Webex Teams
    json_data = request.json
    log.info("\n")
    log.info("WEBHOOK POST RECEIVED:")
    log.info(json_data)
    log.info("\n")

    # Create a Webhook object from the JSON data
    webhook_obj = Webhook(json_data)

    # Get the room details
    room = api.rooms.get(webhook_obj.data.roomId)

    # Get the message details
    message = api.messages.get(webhook_obj.data.id)

    # Get the sender's details
    person = api.people.get(message.personId)

    log.info("NEW MESSAGE IN ROOM '{}'".format(room.title))
    log.info("FROM '{}'".format(person.displayName))
    log.info("MESSAGE '{}'\n".format(message.text))

    # This is a VERY IMPORTANT loop prevention control step.
    # If you respond to all messages...  You will respond to the messages
    # that the bot posts and thereby create a loop condition.
    me = api.people.me()
    if message.personId == me.id:
        # Message was sent by me (bot); do not respond.
        return {'Message': 'OK'}

    else:
        # Message was sent by someone else; parse message and respond.
        if "/CAT" in message.text:
            log.info("FOUND '/CAT'")

            # Get a cat fact
            catfact = get_catfact()
            log.info("SENDING CAT FACT'{}'".format(catfact))

            # Post the fact to the room where the request was received
            api.messages.create(room.id, text=catfact)
        return {'Message': 'OK'}
def post_events_service ( request ) : # Get the POST data sent from Webex Teams json_data = request . json log . info ( "\n" ) log . info ( "WEBHOOK POST RECEIVED:" ) log . info ( json_data ) log . info ( "\n" ) # Create a Webhook object from the JSON data webhook_obj = Webhook ( json_data ) # Get the room details room = api . rooms . get ( webhook_obj . data . roomId ) # Get the message details message = api . messages . get ( webhook_obj . data . id ) # Get the sender's details person = api . people . get ( message . personId ) log . info ( "NEW MESSAGE IN ROOM '{}'" . format ( room . title ) ) log . info ( "FROM '{}'" . format ( person . displayName ) ) log . info ( "MESSAGE '{}'\n" . format ( message . text ) ) # This is a VERY IMPORTANT loop prevention control step. # If you respond to all messages...  You will respond to the messages # that the bot posts and thereby create a loop condition. me = api . people . me ( ) if message . personId == me . id : # Message was sent by me (bot); do not respond. return { 'Message' : 'OK' } else : # Message was sent by someone else; parse message and respond. if "/CAT" in message . text : log . info ( "FOUND '/CAT'" ) # Get a cat fact catfact = get_catfact ( ) log . info ( "SENDING CAT FACT'{}'" . format ( catfact ) ) # Post the fact to the room where the request was received api . messages . create ( room . id , text = catfact ) return { 'Message' : 'OK' }
Respond to inbound webhook JSON HTTP POST from Webex Teams.
Respond to inbound webhook JSON HTTP POST from Webex Teams .