使用Twilio IP消息传递的私人消息传递

时间:2016-01-05 21:07:12

标签: javascript twilio

Twilio中的通信IP消息系统基于频道。我掌握了身份验证,我通过公共渠道实现了通信,现在我想在两个用户之间实现私人通信,我该如何处理呢? 我认为我必须创建一个私人频道

# Create timer
$backgroundTimer = New-Object System.Timers.Timer
# Set interval (ms)
$backgroundTimer.Interval = 500
# Make sure timer stops raising events after each interval
$backgroundTimer.AutoReset = $false

# Have powershell "listen" for the event in the background
Register-ObjectEvent $backgroundTimer -EventName 'Elapsed' -SourceIdentifier 'timerElapsed' -Action {

  # Loop through any completed jobs with data to return, from "oldest" to "newest"
  while(($finishedJob = Get-Job |Where-Object {$_.State -eq 'Completed' -and $_.HasMoreData}|Select-Object -First 1))
  {
    # Update the text box on your WPF form with the results
    # NOTE: the event is executed in a separate scope, thus the "global:" scope prefix
    $global:WPFstsbox.Text = "$(Receive-Job $finishedJob)`n"

    # Clean up the job
    Remove-Job $finishedJob
  }

  # Restart timer
  $backgroundTimer.Start()
}

# Enable the timer
$backgroundTimer.Enabled = $true

私人频道意味着它只是对其他人隐藏,但是如何强制限制用户加入频道以使其更安全?

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

首先,according to the latest documentation,如果您想将频道设置为私有,则需要将其Type设置为private

messagingClient.createChannel({
    uniqueName: 'secret',
    friendlyName: 'Private Chat Channel',
    type: 'private'
}).then(function(channel) {
    console.log('Created private channel:');
    console.log(channel);
});

然后,当您将频道设为私有时,其他用户只能通过邀请加入该频道。这是在API中控制的限制,因此只要您将频道设置为私有,您就不必担心其余部分。

如果有帮助,请告诉我。