WebexPythonSDK
WebexPythonSDK copied to clipboard
Webhook not working
My virtual machine has static ip. But when I write to the bot in the webex nothing happens. The webhook doesn't work. What am I doing wrong? I create webhook on webex: { "items": [ { "id": "*************", "name": "GG", "targetUrl": "http://my_machine_ip:5000/", "resource": "messages", "event": "created", "orgId": "", "createdBy": "", "appId": "", "ownedBy": "creator", "status": "active", "created": "2020-08-03T22:19:20.175Z" } ] }
My bot code: from future import ( absolute_import, division, print_function, unicode_literals, ) from builtins import *
from flask import Flask, request import requests
from webexteamssdk import WebexTeamsAPI, Webhook
from dialog_manager import DialogManager import os
flask_app = Flask(name) WEBEX_TEAMS_ACCESS_TOKEN = os.environ.get('WEBEX_TEAMS_ACCESS_TOKEN') print(WEBEX_TEAMS_ACCESS_TOKEN)
Create the Webex Teams API connection object
api = WebexTeamsAPI()
USERS = {}
@flask_app.route('/', methods=['GET', 'POST']) def webex_teams_webhook_events() if request.method == 'GET': return 'No GET' elif request.method == 'POST': json_data = request.json print("\n") print("WEBHOOK POST RECEIVED:") print(json_data) print("\n")
webhook_obj = Webhook(json_data)
room = api.rooms.get(webhook_obj.data.roomId)
message = api.messages.get(webhook_obj.data.id)
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))
if not message.personId in USERS:
USERS[message.personId] = DialogManager()
# 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:
print("Email:", message.personEmail)
print("Name:", person.displayName)
reply = USERS[message.personId].handle_message(message.text)
api.messages.create(room.id, text=reply)
return 'OK'
if name == 'main': from waitress import serve print('App started...') serve(flask_app, host='0.0.0.0', port=5000)
A few things to check that might help:
- If you change the webhook destination to something else (like Hookbin) do you see incoming webhooks?
- If you use something else to send a webhook-like POST to your app (e.g. CURL:
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
) does your apps see it? - If you're VM is running locally, then webhooks from the Webex cloud are unlikely to make it to your app's listening port without some special configuration. If you'd done that, would be curious to know what it is. If the 'static ip' is a local IP on your network, then you may need to use something like Ngrok to forward incoming POSTs from the cloud to your internal VM/app (or possibly reverse proxy or port-forwarding in your network)
- If your static IP is a real internet address (i.e. your VM is in a cloud hosting situation), then you may need to configure firewall/port-forwarding in your providers settings to enable incoming connections on port 5000
Yes, my static ip is a real internet address (vm on cloud lab). I can get answer with curl from outside, i permit any incoming traffic for my vm, but when i send a message in webex, post request does not come.
Несколько вещей, которые нужно проверить:
- Если вы измените назначение webhook на что-то другое (например, Hookbin ), вы увидите входящие webhooks?
- Если вы используете что-то еще для отправки POST, похожего на webhook, в ваше приложение (например, CURL:)
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
, ваши приложения видят это?- Если ваша виртуальная машина работает локально, то веб-подключения из облака Webex вряд ли попадут в порт прослушивания вашего приложения без какой-либо специальной настройки. Если бы вы сделали это, было бы интересно узнать, что это такое. Если «статический IP-адрес» является локальным IP-адресом в вашей сети, вам может потребоваться использовать что-то вроде Ngrok для пересылки входящих POST-запросов из облака во внутреннюю виртуальную машину / приложение (или, возможно, для обратного прокси-сервера или переадресации портов в вашей сети).
- Если ваш статический IP-адрес является реальным интернет-адресом (т. Е. Ваша виртуальная машина находится в ситуации облачного хостинга), вам может потребоваться настроить брандмауэр / переадресацию портов в настройках вашего провайдера, чтобы разрешить входящие соединения через порт 5000
Closing this issue as it was a troubleshooting request that is now four years old.