examples/bot-example-webpy.py
def POST(self):
        """Respond to inbound webhook JSON HTTP POSTs from Webex Teams."""
        # Get the POST data sent from Webex Teams
        json_data = web.data()
        print("\nWEBHOOK POST RECEIVED:")
        print(json_data, "\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)

        print("NEW MESSAGE IN ROOM '{}'".format(room.title))
        print("FROM '{}'".format(person.displayName))
        print("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 'OK'
        else:
            # Message was sent by someone else; parse message and respond.
            if "/CAT" in message.text:
                print("FOUND '/CAT'")
                # Get a cat fact
                cat_fact = get_catfact()
                print("SENDING CAT FACT '{}'".format(cat_fact))
                # Post the fact to the room where the request was received
                api.messages.create(room.id, text=cat_fact)
        return 'OK'
def POST(self):
        # Get the POST data sent from Webex Teams
        json_data = web.data()
        print("\nWEBHOOK POST RECEIVED:")
        print(json_data, "\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)

        print("NEW MESSAGE IN ROOM '{}'".format(room.title))
        print("FROM '{}'".format(person.displayName))
        print("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 'OK'
        else:
            # Message was sent by someone else; parse message and respond.
            if "/CAT" in message.text:
                print("FOUND '/CAT'")
                # Get a cat fact
                cat_fact = get_catfact()
                print("SENDING CAT FACT '{}'".format(cat_fact))
                # Post the fact to the room where the request was received
                api.messages.create(room.id, text=cat_fact)
        return 'OK'
def POST ( self ) : # Get the POST data sent from Webex Teams json_data = web . data ( ) print ( "\nWEBHOOK POST RECEIVED:" ) print ( json_data , "\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 ) print ( "NEW MESSAGE IN ROOM '{}'" . format ( room . title ) ) print ( "FROM '{}'" . format ( person . displayName ) ) print ( "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 'OK' else : # Message was sent by someone else; parse message and respond. if "/CAT" in message . text : print ( "FOUND '/CAT'" ) # Get a cat fact cat_fact = get_catfact ( ) print ( "SENDING CAT FACT '{}'" . format ( cat_fact ) ) # Post the fact to the room where the request was received api . messages . create ( room . id , text = cat_fact ) return 'OK'
Respond to inbound webhook JSON HTTP POSTs from Webex Teams.
Respond to inbound webhook JSON HTTP POSTs from Webex Teams .