RingCentral JavaScript SDK,WebHook 响应不正确的 HTTP 状态。 HTTP 状态为 405

RingCentral JavaScript SDK, WebHook responds with incorrect HTTP status. HTTP status is 405

当提供以下配置时,其 returns WebHook 总是以不正确的 HTTP 状态响应。 HTTP 状态为 405。

这是 webhook 配置:

var token= access_token;
var _eventFilters = [];
            _eventFilters.push('/restapi/v1.0/account/~/extension/' + 232102004 + '/presence?detailedTelephonyState=true&aggregated=true')

            rcsdk.platform().post('/subscription',
            {
                eventFilters: _eventFilters,
                deliveryMode: {
                    "transportType": "WebHook",
                    "encryption": false,
                    "address": "https://demo.example.com/backend/country-list/web_hook/?auth_token="+token
                }
            })
            .then(function(subscriptionResponse) {
                console.log('Subscription Response: ', subscriptionResponse.json());
            })
            .catch(function(e) {
                console.error(e);
            });

这是我的 Django webhook url:

    @list_route(methods=['get'], url_path='web_hook')
    def create_web_hooks(self, request, **kwargs):

        query_params = request.query_params.dict()
        from django.http import HttpResponse
        response = HttpResponse()
        if 'auth_token' in query_params:
            response['Validation-Token'] = query_params['auth_token']
            response['status'] = 200
            response.write('Hello World')
        return response

提前致谢

在您的 webhook 响应中,response['Validation-Token'] 的内容需要是 RingCentral 创建 webhook HTTP 请求的 Validation-Token header 中存在的值。您的 webhook 侦听器中未使用 RingCentral OAuth 2.0 访问令牌。

您的 webhook 示例在 Python 中,因此这里有一些同时使用 Django 和 Flask 的示例。您应该检查请求 header 是否存在,如果存在,则将值设置为同名的响应 header。下面展示如何设置header.

Django

在 Django 中,请求 headers 在 HttpRequest.META 中可用,它使用它的特定算法重命名 headers。 META 是一个字典,因此您可以通过以下方式访问 header:

response['Validation-Token'] = request.META.get('HTTP_VALIDATION_TOKEN')

response['Validation-Token'] = request.META['HTTP_VALIDATION_TOKEN']

有关 Django 句柄的更多信息,请参阅 HttpRequest.META 的请求和响应 object 文档:

https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest.META

这是header重命名的具体文字:

With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.

烧瓶

使用 Flask,您可以通过以下方式使用 flask.Request dictionary-like object 访问 HTTP 请求 headers:

response['Validation-Token'] = request.headers.get('Validation-Token')

response['Validation-Token'] = request.headers['Validation-Token']

Flask 传入请求数据文档对此进行了讨论:

http://flask.pocoo.org/docs/0.12/api/#incoming-request-data