【问题标题】:How can I play ring on twilio flex UI agent side when incoming calls comes in?来电时,如何在 twilio flex UI 代理端播放铃声?
【发布时间】:2023-03-31 01:47:02
【问题描述】:

每当有任何新来电时,我都会使用this寻找播放声音

【问题讨论】:

    标签: twilio twilio-flex


    【解决方案1】:

    https://www.twilio.com/docs/flex/developer/ui/sound-and-audio 的 Twilio 文档不清楚,所以我从 https://support.twilio.com/hc/en-us/articles/360010784433-How-Do-You-Make-the-Browser-Ring-When-a-Flex-Call-Comes-In- 撤出。这是一个准系统 Flex UI 插件:

    import { FlexPlugin } from "flex-plugin";
    export default class MyPlugin extends FlexPlugin {
      constructor() {
        super("MyPlugin");
      }
      init(flex, manager) {
        const alertSound = new Audio(
          "https://public-path-to-your-audio.mp3"
        );
        alertSound.loop = true;
    
        const resStatus = [
          "accepted",
          "canceled",
          "rejected",
          "rescinded",
          "timeout",
        ];
    
        manager.workerClient.on(
          "reservationCreated",
          function (reservation) {
            if (reservation.task.taskChannelUniqueName === "voice" && reservation.task.attributes.direction === 'inbound') {
              alertSound.play();
            }
            resStatus.forEach((e) => {
              reservation.on(e, () => {
                alertSound.pause();
              });
            });
          }
        );
      }
    }
    

    【讨论】:

    • 此代码运行良好,但缺少方向检查。我的代理报告说它在拨打电话时也在响铃。我用我的修复编辑了你的代码。如果您希望我创建另一个答案,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多