简体   繁体   English

如何使用js和ajax收听实时事件zulip

[英]How to listen to real time event zulip using js and ajax

I have integrated zulip api using js and ajax, the problem is that the exchanged messages are not in real tile so pleasen, how to listen to real time event zulip using js and ajax, here is my js code我已经使用 js 和 ajax 集成了 zulip api,问题是交换的消息不是在真实的 tile 中所以请,如何使用 js 和 Z2705A83A5A0659CEDACE3Z45 收听实时事件

$("#post").click(function () {

var url = 'https://domain_name/api/v1/messages';
var content = $("#postButton").val();
$.ajax({
    type: "post",
    url: url,
    data: {type: 'private', content: content, to: 'khalil@gmail.com'},
    headers: {Authorization: getBasicAuthenticationToken(username, 
    password)},
   

   })






  });


$(function () {
var $msgs = $('#msgs');


 $.ajax({
    type: 'GET',
    url: 'https://domain_name/api/v1/messages',
    data: {num_before: 10, num_after: 1000, use_first_unread_anchor: true},
    headers: {
        "Authorization": getBasicAuthenticationToken(username, password)
    },
    success: function (msgs) {
   
        /*console.log(msgs['messages'][0]['sender_email']);*/
        $.each(msgs.messages, function (i, msg) {
            $msgs.append('<li>' + msg.content + '</li>');
            $msgs.append('<li>' + msg.sender_email + '</li>');
            var who = msg.sender_email;

            insertChat('<p>' + who + '</p>', '<p>' + msg.content +'</p>',0)
        });
    }
});
});

The API you need is the Zulip real-time events API.您需要的API就是Zulip实时事件API。 First, register an event queue with GET /api/v1/register , specifying event_types=["message"] .首先,使用GET /api/v1/register注册一个事件队列,指定event_types=["message"] Then you can get events from the queue by repeatedly long-polling GET /api/v1/events .然后,您可以通过反复长轮询GET /api/v1/events从队列中获取事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM