neru-alpha
Advanced tools
Comparing version 0.0.15 to 0.0.16
import { CommandService, NeruLogger } from './services/index.js'; | ||
import { State } from './providers/index.js'; | ||
import { LogContext } from './types'; | ||
import { Action, Filter, WrappedCallback, LogLevel } from './types'; | ||
import { Action, Filter, WrappedCallback, LogLevel, LogContext } from './types'; | ||
export declare class Instance { | ||
@@ -6,0 +5,0 @@ private commandService; |
@@ -10,2 +10,34 @@ export declare enum Providers { | ||
} | ||
export declare enum Events { | ||
AppKnocking = "app:knocking", | ||
AudioSay = "audio:say", | ||
AudioSayStop = "audio:say:stop", | ||
AudioSayDone = "audio:say:done", | ||
AudioPlay = "audio:play", | ||
AudioPlayStop = "audio:play:stop", | ||
AudioPlayDone = "audio:play:done", | ||
AudioDTMF = "audio:dtmf", | ||
EarmuffOn = "audio:earmuff:on", | ||
EarmuffOff = "audio:earmuff:off", | ||
MuteOn = "audio:mute:on", | ||
MuteOff = "audio:mute:off", | ||
LegStatusUpdate = "leg:status:update", | ||
MemberJoined = "member:joined", | ||
MemberInvited = "member:invited", | ||
MemberLeft = "member:left", | ||
ConversationCreated = "conversation:created" | ||
} | ||
export declare enum CallState { | ||
Joined = "joined", | ||
Invited = "invited" | ||
} | ||
export declare enum MemberActions { | ||
Join = "join" | ||
} | ||
export declare enum ChannelTypes { | ||
PHONE = "phone", | ||
APP = "app", | ||
SIP = "sip", | ||
VBC = "vbc" | ||
} | ||
export declare enum Actions { | ||
@@ -20,1 +52,7 @@ SendMessage = "sendmessage", | ||
} | ||
export declare enum ConversationActions { | ||
CreateConversation = "create-conversation", | ||
InvokeCsApi = "invoke-cs-api", | ||
SubscribeForEvents = "subscribe-conversation-event", | ||
SubscribeForInboundCalls = "subscribe-inbound-call-event" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Actions = exports.Providers = void 0; | ||
exports.ConversationActions = exports.Actions = exports.ChannelTypes = exports.MemberActions = exports.CallState = exports.Events = exports.Providers = void 0; | ||
var Providers; | ||
@@ -14,2 +14,38 @@ (function (Providers) { | ||
})(Providers = exports.Providers || (exports.Providers = {})); | ||
var Events; | ||
(function (Events) { | ||
Events["AppKnocking"] = "app:knocking"; | ||
Events["AudioSay"] = "audio:say"; | ||
Events["AudioSayStop"] = "audio:say:stop"; | ||
Events["AudioSayDone"] = "audio:say:done"; | ||
Events["AudioPlay"] = "audio:play"; | ||
Events["AudioPlayStop"] = "audio:play:stop"; | ||
Events["AudioPlayDone"] = "audio:play:done"; | ||
Events["AudioDTMF"] = "audio:dtmf"; | ||
Events["EarmuffOn"] = "audio:earmuff:on"; | ||
Events["EarmuffOff"] = "audio:earmuff:off"; | ||
Events["MuteOn"] = "audio:mute:on"; | ||
Events["MuteOff"] = "audio:mute:off"; | ||
Events["LegStatusUpdate"] = "leg:status:update"; | ||
Events["MemberJoined"] = "member:joined"; | ||
Events["MemberInvited"] = "member:invited"; | ||
Events["MemberLeft"] = "member:left"; | ||
Events["ConversationCreated"] = "conversation:created"; | ||
})(Events = exports.Events || (exports.Events = {})); | ||
var CallState; | ||
(function (CallState) { | ||
CallState["Joined"] = "joined"; | ||
CallState["Invited"] = "invited"; | ||
})(CallState = exports.CallState || (exports.CallState = {})); | ||
var MemberActions; | ||
(function (MemberActions) { | ||
MemberActions["Join"] = "join"; | ||
})(MemberActions = exports.MemberActions || (exports.MemberActions = {})); | ||
var ChannelTypes; | ||
(function (ChannelTypes) { | ||
ChannelTypes["PHONE"] = "phone"; | ||
ChannelTypes["APP"] = "app"; | ||
ChannelTypes["SIP"] = "sip"; | ||
ChannelTypes["VBC"] = "vbc"; | ||
})(ChannelTypes = exports.ChannelTypes || (exports.ChannelTypes = {})); | ||
var Actions; | ||
@@ -25,1 +61,8 @@ (function (Actions) { | ||
})(Actions = exports.Actions || (exports.Actions = {})); | ||
var ConversationActions; | ||
(function (ConversationActions) { | ||
ConversationActions["CreateConversation"] = "create-conversation"; | ||
ConversationActions["InvokeCsApi"] = "invoke-cs-api"; | ||
ConversationActions["SubscribeForEvents"] = "subscribe-conversation-event"; | ||
ConversationActions["SubscribeForInboundCalls"] = "subscribe-inbound-call-event"; | ||
})(ConversationActions = exports.ConversationActions || (exports.ConversationActions = {})); |
@@ -1,32 +0,37 @@ | ||
import type { Contact } from '../types'; | ||
import { Instance } from '../instance.js'; | ||
import { RequestInterface, RequestInterfaceForCallbacks } from './requestInterface.js'; | ||
import { AppKnockingEvent, Channel, Filter, SayTextParams, PlayStreamParams, ChannelPhoneEndpoint } from '../types'; | ||
declare class Conversation { | ||
readonly name: string; | ||
id: string; | ||
name: string; | ||
private instance; | ||
constructor(name: string, instance: Instance); | ||
createConversation: (name: any, displayName: any) => RequestInterface; | ||
acceptInboundCall: (appKnockingEvt: any) => RequestInterface; | ||
inviteMember: (name: any, channel: any) => RequestInterface; | ||
addUser: (name: any) => RequestInterface; | ||
transferMember: (user_id: any, leg_id: any) => RequestInterface; | ||
sayText: (params: any) => RequestInterface; | ||
sayStop: (sayId: any, to: any) => RequestInterface; | ||
playStream: (params: any, memberId: any) => RequestInterface; | ||
playStop: (playId: any, to: any) => RequestInterface; | ||
earmuff: (memberId: any, enable: any) => RequestInterface; | ||
mute: (memberId: any, enable: any) => RequestInterface; | ||
listenForEvents: (callback: any, filters: any) => RequestInterfaceForCallbacks; | ||
onConversationCreated: (callback: any) => RequestInterfaceForCallbacks; | ||
onSay: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlay: (callback: any) => RequestInterfaceForCallbacks; | ||
onSayStop: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlayStop: (callback: any) => RequestInterfaceForCallbacks; | ||
onSayDone: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlayDone: (callback: any) => RequestInterfaceForCallbacks; | ||
onLegStatusUpdate: (callback: any) => RequestInterfaceForCallbacks; | ||
onMemberJoined: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onMemberInvited: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onMemberLeft: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onDTMF: (callback: any) => RequestInterfaceForCallbacks; | ||
constructor(id: string, name: string, instance: Instance); | ||
createConversation: (name: string, displayName: string) => RequestInterface; | ||
acceptInboundCall: (appKnockingEvent: AppKnockingEvent) => RequestInterface; | ||
inviteMember: (name: string, channel: Channel) => RequestInterface; | ||
addUser: (name: string) => RequestInterface; | ||
transferMember: (userId: string, legId: string) => RequestInterface; | ||
sayText: (params: SayTextParams) => RequestInterface; | ||
sayStop: (sayId: string, to?: string) => RequestInterface; | ||
playStream: (params: PlayStreamParams) => RequestInterface; | ||
playStop: (playId: string, to?: string) => RequestInterface; | ||
private earmuff; | ||
earmuffOn(to: string, from?: string): RequestInterface; | ||
earmuffOff(to: string, from?: string): RequestInterface; | ||
private mute; | ||
muteOn(to: string, from?: string): RequestInterface; | ||
muteOff(to: string, from?: string): RequestInterface; | ||
listenForEvents: (callback: string, filters: Filter[]) => RequestInterfaceForCallbacks; | ||
onConversationCreated: (callback: string) => RequestInterfaceForCallbacks; | ||
onSay: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlay: (callback: string) => RequestInterfaceForCallbacks; | ||
onSayStop: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlayStop: (callback: string) => RequestInterfaceForCallbacks; | ||
onSayDone: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlayDone: (callback: string) => RequestInterfaceForCallbacks; | ||
onLegStatusUpdate: (callback: string) => RequestInterfaceForCallbacks; | ||
onMemberJoined: (callback: string, memberName?: string) => RequestInterfaceForCallbacks; | ||
onMemberInvited: (callback: string, memberName: string) => RequestInterfaceForCallbacks; | ||
onMemberLeft: (callback: string, memberName: string) => RequestInterfaceForCallbacks; | ||
onDTMF: (callback: string) => RequestInterfaceForCallbacks; | ||
} | ||
@@ -36,6 +41,6 @@ export declare class ConversationService { | ||
constructor(instance: Instance); | ||
onInboundCall(callback: string, to: Contact, from?: Contact): RequestInterfaceForCallbacks; | ||
createConversation(name: any, displayName: any): Promise<Conversation>; | ||
getConversation(name: string): Conversation; | ||
onInboundCall(callback: string, to: ChannelPhoneEndpoint, from?: ChannelPhoneEndpoint): RequestInterfaceForCallbacks; | ||
createConversation(name: string, displayName: string): Promise<Conversation>; | ||
getConversationById(id: string, name: string): Conversation; | ||
} | ||
export {}; |
@@ -43,4 +43,5 @@ "use strict"; | ||
var Conversation = /** @class */ (function () { | ||
function Conversation(name, instance) { | ||
function Conversation(id, name, instance) { | ||
var _this = this; | ||
this.id = id; | ||
this.name = name; | ||
@@ -51,3 +52,4 @@ this.instance = instance; | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'create-conversation', | ||
action: constants_js_1.ConversationActions.CreateConversation, | ||
description: 'Create new conversation', | ||
payload: { | ||
@@ -63,37 +65,36 @@ neruCID: name, | ||
}; | ||
this.acceptInboundCall = function (appKnockingEvt) { | ||
var user_id = appKnockingEvt.body.user.id; | ||
var knocking_id = appKnockingEvt.from; | ||
var channel = appKnockingEvt.body.channel; | ||
var acceptInboundCallBody = { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id: knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: 'joined', | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}; | ||
this.acceptInboundCall = function (appKnockingEvent) { | ||
var user_id = appKnockingEvent.body.user.id; | ||
var knocking_id = appKnockingEvent.from; | ||
var channel = appKnockingEvent.body.channel; | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Accept inbound call - Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: acceptInboundCallBody, | ||
csBody: { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id: knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: constants_js_1.CallState.Joined, | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}, | ||
}, | ||
@@ -106,7 +107,7 @@ }; | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Invite Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
@@ -118,4 +119,4 @@ neruMID: _this.name + "_" + name, | ||
}, | ||
action: 'join', | ||
state: 'invited', | ||
action: constants_js_1.MemberActions.Join, | ||
state: constants_js_1.CallState.Invited, | ||
channel: channel, | ||
@@ -130,7 +131,7 @@ }, | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Create User', | ||
payload: { | ||
url: '/users', | ||
method: 'POST', | ||
url: "/users", | ||
method: "POST", | ||
neruCID: _this.name, | ||
@@ -145,20 +146,20 @@ csBody: { | ||
}; | ||
this.transferMember = function (user_id, leg_id) { | ||
this.transferMember = function (userId, legId) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Transfer Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
action: 'join', | ||
action: constants_js_1.MemberActions.Join, | ||
channel: { | ||
type: 'phone', | ||
id: leg_id, | ||
type: constants_js_1.ChannelTypes.PHONE, | ||
id: legId, | ||
}, | ||
state: 'joined', | ||
state: constants_js_1.CallState.Joined, | ||
user: { | ||
id: user_id, | ||
id: userId, | ||
}, | ||
@@ -173,13 +174,13 @@ }, | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Send Text', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Play text via TTS', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:say', | ||
type: constants_js_1.Events.AudioSay, | ||
body: { | ||
text: params.text, | ||
voice_name: params.voice_name || 'Amy', | ||
voice_name: params.voiceName || 'Amy', | ||
level: params.level || 1, | ||
@@ -193,2 +194,8 @@ queue: !!params.queue, | ||
}; | ||
if (params.language) { | ||
action.payload.csBody.body.language = params.language; | ||
} | ||
if (params.style) { | ||
action.payload.csBody.body.style = params.style; | ||
} | ||
return new requestInterface_js_1.RequestInterface(_this.instance, action); | ||
@@ -199,10 +206,10 @@ }; | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Send Stop Event', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: "Send Stop Event", | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:say:stop', | ||
type: constants_js_1.Events.AudioSayStop, | ||
body: { | ||
@@ -218,14 +225,13 @@ say_id: sayId, | ||
}; | ||
this.playStream = function (params, memberId) { | ||
this.playStream = function (params) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Sending Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:play', | ||
to: memberId, | ||
type: constants_js_1.Events.AudioPlay, | ||
body: params, | ||
@@ -240,10 +246,10 @@ }, | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Stopping Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:play:stop', | ||
type: constants_js_1.Events.AudioPlayStop, | ||
body: { | ||
@@ -259,42 +265,6 @@ play_id: playId, | ||
}; | ||
this.earmuff = function (memberId, enable) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Sending earmuff event', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
neruCID: _this.name, | ||
csBody: { | ||
type: enable ? 'audio:earmuff:on' : 'audio:earmuff:off', | ||
to: memberId, | ||
from: memberId, | ||
}, | ||
}, | ||
}; | ||
return new requestInterface_js_1.RequestInterface(_this.instance, action); | ||
}; | ||
this.mute = function (memberId, enable) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Mute Call', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
neruCID: _this.name, | ||
csBody: { | ||
type: enable ? 'audio:mute:on' : 'audio:mute:off', | ||
to: memberId, | ||
from: memberId, | ||
}, | ||
}, | ||
}; | ||
return new requestInterface_js_1.RequestInterface(_this.instance, action); | ||
}; | ||
this.listenForEvents = function (callback, filters) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'subscribe-conversation-event', | ||
action: constants_js_1.ConversationActions.SubscribeForEvents, | ||
payload: { | ||
@@ -312,3 +282,3 @@ neruCID: _this.name, | ||
op: 'contains', | ||
values: ['conversation:created'], | ||
values: [constants_js_1.Events.ConversationCreated], | ||
}, | ||
@@ -328,4 +298,9 @@ { | ||
op: 'contains', | ||
values: ['audio:say'], | ||
values: [constants_js_1.Events.AudioSay], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -339,4 +314,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play'], | ||
values: [constants_js_1.Events.AudioPlay], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -350,4 +330,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:say:stop'], | ||
values: [constants_js_1.Events.AudioSayStop], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -361,4 +346,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play:stop'], | ||
values: [constants_js_1.Events.AudioPlayStop], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -372,4 +362,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:say:done'], | ||
values: [constants_js_1.Events.AudioSayDone], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -383,4 +378,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play:done'], | ||
values: [constants_js_1.Events.AudioPlayDone], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -394,4 +394,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['leg:status:update'], | ||
values: [constants_js_1.Events.LegStatusUpdate], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -405,9 +410,14 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['member:joined'], | ||
values: [constants_js_1.Events.MemberJoined], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
if (memberName) { | ||
filters.push({ | ||
path: 'body.user.name', | ||
op: 'contains', | ||
path: "body.user.name", | ||
op: "contains", | ||
values: [memberName], | ||
@@ -423,4 +433,9 @@ }); | ||
op: 'contains', | ||
values: ['member:invited'], | ||
values: [constants_js_1.Events.MemberInvited], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -441,4 +456,9 @@ if (memberName) { | ||
op: 'contains', | ||
values: ['member:left'], | ||
values: [constants_js_1.Events.MemberLeft], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -459,4 +479,9 @@ if (memberName) { | ||
op: 'contains', | ||
values: ['audio:dtmf'], | ||
values: [constants_js_1.Events.AudioDTMF], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -466,4 +491,61 @@ return _this.listenForEvents(callback, filters); | ||
this.name = name; | ||
this.id = id; | ||
this.instance = instance; | ||
} | ||
Conversation.prototype.earmuff = function (enable, to, from) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Sending earmuff event', | ||
payload: { | ||
url: "/conversations/" + this.id + "/events", | ||
method: "POST", | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? constants_js_1.Events.EarmuffOn : constants_js_1.Events.EarmuffOff, | ||
to: to, | ||
from: from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id, | ||
// }, | ||
}, | ||
}, | ||
}; | ||
return new requestInterface_js_1.RequestInterface(this.instance, action); | ||
}; | ||
Conversation.prototype.earmuffOn = function (to, from) { | ||
return this.earmuff(true, to, from); | ||
}; | ||
Conversation.prototype.earmuffOff = function (to, from) { | ||
return this.earmuff(false, to, from); | ||
}; | ||
Conversation.prototype.mute = function (enable, to, from) { | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: constants_js_1.ConversationActions.InvokeCsApi, | ||
description: 'Mute Call', | ||
payload: { | ||
url: "/conversations/" + this.id + "/events", | ||
method: "POST", | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? constants_js_1.Events.MuteOn : constants_js_1.Events.MuteOff, | ||
to: to, | ||
from: from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id | ||
// } | ||
}, | ||
}, | ||
}; | ||
return new requestInterface_js_1.RequestInterface(this.instance, action); | ||
}; | ||
Conversation.prototype.muteOn = function (to, from) { | ||
return this.mute(true, to, from); | ||
}; | ||
Conversation.prototype.muteOff = function (to, from) { | ||
return this.mute(false, to, from); | ||
}; | ||
return Conversation; | ||
@@ -476,13 +558,12 @@ }()); | ||
ConversationService.prototype.onInboundCall = function (callback, to, from) { | ||
var payload = { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
}; | ||
if (from) | ||
payload.from = from; | ||
var action = { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'subscribe-inbound-call-event', | ||
payload: payload, | ||
action: constants_js_1.ConversationActions.SubscribeForInboundCalls, | ||
payload: { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
}, | ||
}; | ||
if (from) | ||
action.payload.from = from; | ||
return new requestInterface_js_1.RequestInterfaceForCallbacks(this.instance, action); | ||
@@ -492,3 +573,3 @@ }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var action; | ||
var action, res; | ||
return __generator(this, function (_a) { | ||
@@ -499,3 +580,3 @@ switch (_a.label) { | ||
provider: constants_js_1.Providers.Conversation, | ||
action: 'create-conversation', | ||
action: constants_js_1.ConversationActions.CreateConversation, | ||
payload: { | ||
@@ -511,7 +592,4 @@ neruCID: name, | ||
case 1: | ||
_a.sent(); | ||
// TODO: what if the client would need the response? | ||
// TODO: one of the solutions would be to pull all the meaningful information | ||
// TODO: out of the response and pass it to the Conversation's constructor | ||
return [2 /*return*/, new Conversation(name, this.instance)]; | ||
res = _a.sent(); | ||
return [2 /*return*/, new Conversation(res.id, name, this.instance)]; | ||
} | ||
@@ -521,4 +599,4 @@ }); | ||
}; | ||
ConversationService.prototype.getConversation = function (name) { | ||
return new Conversation(name, this.instance); | ||
ConversationService.prototype.getConversationById = function (id, name) { | ||
return new Conversation(id, name, this.instance); | ||
}; | ||
@@ -525,0 +603,0 @@ return ConversationService; |
@@ -86,8 +86,8 @@ "use strict"; | ||
}, | ||
{ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}, | ||
]; | ||
filters.push({ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}); | ||
if (to.number) { | ||
@@ -94,0 +94,0 @@ filters.push({ |
@@ -13,3 +13,3 @@ import { CommandService, NeruLogger } from '../services/index.js'; | ||
hgetall: (htable: string) => Promise<any>; | ||
hmget: (htable: string, keys: [string]) => Promise<any>; | ||
hmget: (htable: string, keys: string[]) => Promise<any>; | ||
hvals: (htable: string) => Promise<any>; | ||
@@ -16,0 +16,0 @@ hget: (htable: string, key: string) => Promise<any>; |
@@ -209,3 +209,2 @@ "use strict"; | ||
args = Object.keys(keyValuePairs).flatMap(function (k) { return [k, JSON.stringify(keyValuePairs[k])]; }); | ||
console.log('hset args', args); | ||
cmd = { | ||
@@ -212,0 +211,0 @@ operation: 'HSET', |
@@ -1,2 +0,1 @@ | ||
import { Headers } from 'got'; | ||
import { Config } from '../types'; | ||
@@ -6,3 +5,3 @@ export declare class Utils { | ||
constructor(config: Config); | ||
isJson(headers: Headers): boolean; | ||
isJson(headers: Record<string, string>): boolean; | ||
getExecutionUrl(func: string): string; | ||
@@ -9,0 +8,0 @@ getQueueUrl(func: string): string; |
@@ -10,1 +10,2 @@ declare const config: { | ||
export default config; | ||
//# sourceMappingURL=config.d.ts.map |
@@ -10,1 +10,2 @@ var config = { | ||
export default config; | ||
//# sourceMappingURL=config.js.map |
import { Config } from '../types'; | ||
declare const finalConfig: Config; | ||
export default finalConfig; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -27,1 +27,2 @@ var __assign = (this && this.__assign) || function () { | ||
export default finalConfig; | ||
//# sourceMappingURL=index.js.map |
export {}; | ||
//# sourceMappingURL=container.d.ts.map |
@@ -6,1 +6,2 @@ import { container } from 'tsyringe'; | ||
}); | ||
//# sourceMappingURL=container.js.map |
@@ -12,1 +12,2 @@ import 'reflect-metadata'; | ||
export declare const neru: Neru; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -8,1 +8,2 @@ import 'reflect-metadata'; | ||
export var neru = container.resolve(Neru); | ||
//# sourceMappingURL=index.js.map |
import { CommandService, NeruLogger } from './services/index.js'; | ||
import { State } from './providers/index.js'; | ||
import { LogContext } from './types'; | ||
import { Action, Filter, WrappedCallback, LogLevel } from './types'; | ||
import { Action, Filter, WrappedCallback, LogLevel, LogContext } from './types'; | ||
export declare class Instance { | ||
@@ -25,1 +24,2 @@ private commandService; | ||
} | ||
//# sourceMappingURL=instance.d.ts.map |
@@ -190,1 +190,2 @@ var __assign = (this && this.__assign) || function () { | ||
export { Instance }; | ||
//# sourceMappingURL=instance.js.map |
@@ -10,1 +10,2 @@ import type { Request } from 'express'; | ||
} | ||
//# sourceMappingURL=neru.d.ts.map |
@@ -44,1 +44,2 @@ import { v4 as uuid } from 'uuid'; | ||
export { Neru }; | ||
//# sourceMappingURL=neru.js.map |
@@ -9,1 +9,2 @@ import { CommandService } from '../services/index.js'; | ||
} | ||
//# sourceMappingURL=assets.d.ts.map |
@@ -80,1 +80,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
export { Assets }; | ||
//# sourceMappingURL=assets.js.map |
@@ -10,2 +10,34 @@ export declare enum Providers { | ||
} | ||
export declare enum Events { | ||
AppKnocking = "app:knocking", | ||
AudioSay = "audio:say", | ||
AudioSayStop = "audio:say:stop", | ||
AudioSayDone = "audio:say:done", | ||
AudioPlay = "audio:play", | ||
AudioPlayStop = "audio:play:stop", | ||
AudioPlayDone = "audio:play:done", | ||
AudioDTMF = "audio:dtmf", | ||
EarmuffOn = "audio:earmuff:on", | ||
EarmuffOff = "audio:earmuff:off", | ||
MuteOn = "audio:mute:on", | ||
MuteOff = "audio:mute:off", | ||
LegStatusUpdate = "leg:status:update", | ||
MemberJoined = "member:joined", | ||
MemberInvited = "member:invited", | ||
MemberLeft = "member:left", | ||
ConversationCreated = "conversation:created" | ||
} | ||
export declare enum CallState { | ||
Joined = "joined", | ||
Invited = "invited" | ||
} | ||
export declare enum MemberActions { | ||
Join = "join" | ||
} | ||
export declare enum ChannelTypes { | ||
PHONE = "phone", | ||
APP = "app", | ||
SIP = "sip", | ||
VBC = "vbc" | ||
} | ||
export declare enum Actions { | ||
@@ -20,1 +52,8 @@ SendMessage = "sendmessage", | ||
} | ||
export declare enum ConversationActions { | ||
CreateConversation = "create-conversation", | ||
InvokeCsApi = "invoke-cs-api", | ||
SubscribeForEvents = "subscribe-conversation-event", | ||
SubscribeForInboundCalls = "subscribe-inbound-call-event" | ||
} | ||
//# sourceMappingURL=constants.d.ts.map |
@@ -11,2 +11,38 @@ export var Providers; | ||
})(Providers || (Providers = {})); | ||
export var Events; | ||
(function (Events) { | ||
Events["AppKnocking"] = "app:knocking"; | ||
Events["AudioSay"] = "audio:say"; | ||
Events["AudioSayStop"] = "audio:say:stop"; | ||
Events["AudioSayDone"] = "audio:say:done"; | ||
Events["AudioPlay"] = "audio:play"; | ||
Events["AudioPlayStop"] = "audio:play:stop"; | ||
Events["AudioPlayDone"] = "audio:play:done"; | ||
Events["AudioDTMF"] = "audio:dtmf"; | ||
Events["EarmuffOn"] = "audio:earmuff:on"; | ||
Events["EarmuffOff"] = "audio:earmuff:off"; | ||
Events["MuteOn"] = "audio:mute:on"; | ||
Events["MuteOff"] = "audio:mute:off"; | ||
Events["LegStatusUpdate"] = "leg:status:update"; | ||
Events["MemberJoined"] = "member:joined"; | ||
Events["MemberInvited"] = "member:invited"; | ||
Events["MemberLeft"] = "member:left"; | ||
Events["ConversationCreated"] = "conversation:created"; | ||
})(Events || (Events = {})); | ||
export var CallState; | ||
(function (CallState) { | ||
CallState["Joined"] = "joined"; | ||
CallState["Invited"] = "invited"; | ||
})(CallState || (CallState = {})); | ||
export var MemberActions; | ||
(function (MemberActions) { | ||
MemberActions["Join"] = "join"; | ||
})(MemberActions || (MemberActions = {})); | ||
export var ChannelTypes; | ||
(function (ChannelTypes) { | ||
ChannelTypes["PHONE"] = "phone"; | ||
ChannelTypes["APP"] = "app"; | ||
ChannelTypes["SIP"] = "sip"; | ||
ChannelTypes["VBC"] = "vbc"; | ||
})(ChannelTypes || (ChannelTypes = {})); | ||
export var Actions; | ||
@@ -22,1 +58,9 @@ (function (Actions) { | ||
})(Actions || (Actions = {})); | ||
export var ConversationActions; | ||
(function (ConversationActions) { | ||
ConversationActions["CreateConversation"] = "create-conversation"; | ||
ConversationActions["InvokeCsApi"] = "invoke-cs-api"; | ||
ConversationActions["SubscribeForEvents"] = "subscribe-conversation-event"; | ||
ConversationActions["SubscribeForInboundCalls"] = "subscribe-inbound-call-event"; | ||
})(ConversationActions || (ConversationActions = {})); | ||
//# sourceMappingURL=constants.js.map |
@@ -1,32 +0,37 @@ | ||
import type { Contact } from '../types'; | ||
import { Instance } from '../instance.js'; | ||
import { RequestInterface, RequestInterfaceForCallbacks } from './requestInterface.js'; | ||
import { AppKnockingEvent, Channel, Filter, SayTextParams, PlayStreamParams, ChannelPhoneEndpoint } from '../types'; | ||
declare class Conversation { | ||
readonly name: string; | ||
id: string; | ||
name: string; | ||
private instance; | ||
constructor(name: string, instance: Instance); | ||
createConversation: (name: any, displayName: any) => RequestInterface; | ||
acceptInboundCall: (appKnockingEvt: any) => RequestInterface; | ||
inviteMember: (name: any, channel: any) => RequestInterface; | ||
addUser: (name: any) => RequestInterface; | ||
transferMember: (user_id: any, leg_id: any) => RequestInterface; | ||
sayText: (params: any) => RequestInterface; | ||
sayStop: (sayId: any, to: any) => RequestInterface; | ||
playStream: (params: any, memberId: any) => RequestInterface; | ||
playStop: (playId: any, to: any) => RequestInterface; | ||
earmuff: (memberId: any, enable: any) => RequestInterface; | ||
mute: (memberId: any, enable: any) => RequestInterface; | ||
listenForEvents: (callback: any, filters: any) => RequestInterfaceForCallbacks; | ||
onConversationCreated: (callback: any) => RequestInterfaceForCallbacks; | ||
onSay: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlay: (callback: any) => RequestInterfaceForCallbacks; | ||
onSayStop: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlayStop: (callback: any) => RequestInterfaceForCallbacks; | ||
onSayDone: (callback: any) => RequestInterfaceForCallbacks; | ||
onPlayDone: (callback: any) => RequestInterfaceForCallbacks; | ||
onLegStatusUpdate: (callback: any) => RequestInterfaceForCallbacks; | ||
onMemberJoined: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onMemberInvited: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onMemberLeft: (callback: any, memberName: any) => RequestInterfaceForCallbacks; | ||
onDTMF: (callback: any) => RequestInterfaceForCallbacks; | ||
constructor(id: string, name: string, instance: Instance); | ||
createConversation: (name: string, displayName: string) => RequestInterface; | ||
acceptInboundCall: (appKnockingEvent: AppKnockingEvent) => RequestInterface; | ||
inviteMember: (name: string, channel: Channel) => RequestInterface; | ||
addUser: (name: string) => RequestInterface; | ||
transferMember: (userId: string, legId: string) => RequestInterface; | ||
sayText: (params: SayTextParams) => RequestInterface; | ||
sayStop: (sayId: string, to?: string) => RequestInterface; | ||
playStream: (params: PlayStreamParams) => RequestInterface; | ||
playStop: (playId: string, to?: string) => RequestInterface; | ||
private earmuff; | ||
earmuffOn(to: string, from?: string): RequestInterface; | ||
earmuffOff(to: string, from?: string): RequestInterface; | ||
private mute; | ||
muteOn(to: string, from?: string): RequestInterface; | ||
muteOff(to: string, from?: string): RequestInterface; | ||
listenForEvents: (callback: string, filters: Filter[]) => RequestInterfaceForCallbacks; | ||
onConversationCreated: (callback: string) => RequestInterfaceForCallbacks; | ||
onSay: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlay: (callback: string) => RequestInterfaceForCallbacks; | ||
onSayStop: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlayStop: (callback: string) => RequestInterfaceForCallbacks; | ||
onSayDone: (callback: string) => RequestInterfaceForCallbacks; | ||
onPlayDone: (callback: string) => RequestInterfaceForCallbacks; | ||
onLegStatusUpdate: (callback: string) => RequestInterfaceForCallbacks; | ||
onMemberJoined: (callback: string, memberName?: string) => RequestInterfaceForCallbacks; | ||
onMemberInvited: (callback: string, memberName: string) => RequestInterfaceForCallbacks; | ||
onMemberLeft: (callback: string, memberName: string) => RequestInterfaceForCallbacks; | ||
onDTMF: (callback: string) => RequestInterfaceForCallbacks; | ||
} | ||
@@ -36,6 +41,7 @@ export declare class ConversationService { | ||
constructor(instance: Instance); | ||
onInboundCall(callback: string, to: Contact, from?: Contact): RequestInterfaceForCallbacks; | ||
createConversation(name: any, displayName: any): Promise<Conversation>; | ||
getConversation(name: string): Conversation; | ||
onInboundCall(callback: string, to: ChannelPhoneEndpoint, from?: ChannelPhoneEndpoint): RequestInterfaceForCallbacks; | ||
createConversation(name: string, displayName: string): Promise<Conversation>; | ||
getConversationById(id: string, name: string): Conversation; | ||
} | ||
export {}; | ||
//# sourceMappingURL=conversation.d.ts.map |
@@ -37,7 +37,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { Providers } from './constants.js'; | ||
import { Providers, Events, CallState, ChannelTypes, MemberActions, ConversationActions } from './constants.js'; | ||
import { RequestInterface, RequestInterfaceForCallbacks } from './requestInterface.js'; | ||
var Conversation = /** @class */ (function () { | ||
function Conversation(name, instance) { | ||
function Conversation(id, name, instance) { | ||
var _this = this; | ||
this.id = id; | ||
this.name = name; | ||
@@ -48,3 +49,4 @@ this.instance = instance; | ||
provider: Providers.Conversation, | ||
action: 'create-conversation', | ||
action: ConversationActions.CreateConversation, | ||
description: 'Create new conversation', | ||
payload: { | ||
@@ -60,37 +62,36 @@ neruCID: name, | ||
}; | ||
this.acceptInboundCall = function (appKnockingEvt) { | ||
var user_id = appKnockingEvt.body.user.id; | ||
var knocking_id = appKnockingEvt.from; | ||
var channel = appKnockingEvt.body.channel; | ||
var acceptInboundCallBody = { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id: knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: 'joined', | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}; | ||
this.acceptInboundCall = function (appKnockingEvent) { | ||
var user_id = appKnockingEvent.body.user.id; | ||
var knocking_id = appKnockingEvent.from; | ||
var channel = appKnockingEvent.body.channel; | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Accept inbound call - Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: acceptInboundCallBody, | ||
csBody: { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id: knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: CallState.Joined, | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}, | ||
}, | ||
@@ -103,7 +104,7 @@ }; | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Invite Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
@@ -115,4 +116,4 @@ neruMID: _this.name + "_" + name, | ||
}, | ||
action: 'join', | ||
state: 'invited', | ||
action: MemberActions.Join, | ||
state: CallState.Invited, | ||
channel: channel, | ||
@@ -127,7 +128,7 @@ }, | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Create User', | ||
payload: { | ||
url: '/users', | ||
method: 'POST', | ||
url: "/users", | ||
method: "POST", | ||
neruCID: _this.name, | ||
@@ -142,20 +143,20 @@ csBody: { | ||
}; | ||
this.transferMember = function (user_id, leg_id) { | ||
this.transferMember = function (userId, legId) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Transfer Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/members", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
action: 'join', | ||
action: MemberActions.Join, | ||
channel: { | ||
type: 'phone', | ||
id: leg_id, | ||
type: ChannelTypes.PHONE, | ||
id: legId, | ||
}, | ||
state: 'joined', | ||
state: CallState.Joined, | ||
user: { | ||
id: user_id, | ||
id: userId, | ||
}, | ||
@@ -170,13 +171,13 @@ }, | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Send Text', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Play text via TTS', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:say', | ||
type: Events.AudioSay, | ||
body: { | ||
text: params.text, | ||
voice_name: params.voice_name || 'Amy', | ||
voice_name: params.voiceName || 'Amy', | ||
level: params.level || 1, | ||
@@ -190,2 +191,8 @@ queue: !!params.queue, | ||
}; | ||
if (params.language) { | ||
action.payload.csBody.body.language = params.language; | ||
} | ||
if (params.style) { | ||
action.payload.csBody.body.style = params.style; | ||
} | ||
return new RequestInterface(_this.instance, action); | ||
@@ -196,10 +203,10 @@ }; | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Send Stop Event', | ||
action: ConversationActions.InvokeCsApi, | ||
description: "Send Stop Event", | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:say:stop', | ||
type: Events.AudioSayStop, | ||
body: { | ||
@@ -215,14 +222,13 @@ say_id: sayId, | ||
}; | ||
this.playStream = function (params, memberId) { | ||
this.playStream = function (params) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Sending Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:play', | ||
to: memberId, | ||
type: Events.AudioPlay, | ||
body: params, | ||
@@ -237,10 +243,10 @@ }, | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Stopping Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: "/conversations/" + _this.id + "/events", | ||
method: "POST", | ||
neruCID: _this.name, | ||
csBody: { | ||
type: 'audio:play:stop', | ||
type: Events.AudioPlayStop, | ||
body: { | ||
@@ -256,42 +262,6 @@ play_id: playId, | ||
}; | ||
this.earmuff = function (memberId, enable) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Sending earmuff event', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
neruCID: _this.name, | ||
csBody: { | ||
type: enable ? 'audio:earmuff:on' : 'audio:earmuff:off', | ||
to: memberId, | ||
from: memberId, | ||
}, | ||
}, | ||
}; | ||
return new RequestInterface(_this.instance, action); | ||
}; | ||
this.mute = function (memberId, enable) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Mute Call', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
neruCID: _this.name, | ||
csBody: { | ||
type: enable ? 'audio:mute:on' : 'audio:mute:off', | ||
to: memberId, | ||
from: memberId, | ||
}, | ||
}, | ||
}; | ||
return new RequestInterface(_this.instance, action); | ||
}; | ||
this.listenForEvents = function (callback, filters) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'subscribe-conversation-event', | ||
action: ConversationActions.SubscribeForEvents, | ||
payload: { | ||
@@ -309,3 +279,3 @@ neruCID: _this.name, | ||
op: 'contains', | ||
values: ['conversation:created'], | ||
values: [Events.ConversationCreated], | ||
}, | ||
@@ -325,4 +295,9 @@ { | ||
op: 'contains', | ||
values: ['audio:say'], | ||
values: [Events.AudioSay], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -336,4 +311,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play'], | ||
values: [Events.AudioPlay], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -347,4 +327,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:say:stop'], | ||
values: [Events.AudioSayStop], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -358,4 +343,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play:stop'], | ||
values: [Events.AudioPlayStop], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -369,4 +359,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:say:done'], | ||
values: [Events.AudioSayDone], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -380,4 +375,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['audio:play:done'], | ||
values: [Events.AudioPlayDone], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -391,4 +391,9 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['leg:status:update'], | ||
values: [Events.LegStatusUpdate], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -402,9 +407,14 @@ return _this.listenForEvents(callback, filters); | ||
op: 'contains', | ||
values: ['member:joined'], | ||
values: [Events.MemberJoined], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
if (memberName) { | ||
filters.push({ | ||
path: 'body.user.name', | ||
op: 'contains', | ||
path: "body.user.name", | ||
op: "contains", | ||
values: [memberName], | ||
@@ -420,4 +430,9 @@ }); | ||
op: 'contains', | ||
values: ['member:invited'], | ||
values: [Events.MemberInvited], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -438,4 +453,9 @@ if (memberName) { | ||
op: 'contains', | ||
values: ['member:left'], | ||
values: [Events.MemberLeft], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -456,4 +476,9 @@ if (memberName) { | ||
op: 'contains', | ||
values: ['audio:dtmf'], | ||
values: [Events.AudioDTMF], | ||
}, | ||
{ | ||
path: "conversation_id", | ||
op: "contains", | ||
values: [_this.id], | ||
}, | ||
]; | ||
@@ -463,4 +488,61 @@ return _this.listenForEvents(callback, filters); | ||
this.name = name; | ||
this.id = id; | ||
this.instance = instance; | ||
} | ||
Conversation.prototype.earmuff = function (enable, to, from) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Sending earmuff event', | ||
payload: { | ||
url: "/conversations/" + this.id + "/events", | ||
method: "POST", | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? Events.EarmuffOn : Events.EarmuffOff, | ||
to: to, | ||
from: from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id, | ||
// }, | ||
}, | ||
}, | ||
}; | ||
return new RequestInterface(this.instance, action); | ||
}; | ||
Conversation.prototype.earmuffOn = function (to, from) { | ||
return this.earmuff(true, to, from); | ||
}; | ||
Conversation.prototype.earmuffOff = function (to, from) { | ||
return this.earmuff(false, to, from); | ||
}; | ||
Conversation.prototype.mute = function (enable, to, from) { | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Mute Call', | ||
payload: { | ||
url: "/conversations/" + this.id + "/events", | ||
method: "POST", | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? Events.MuteOn : Events.MuteOff, | ||
to: to, | ||
from: from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id | ||
// } | ||
}, | ||
}, | ||
}; | ||
return new RequestInterface(this.instance, action); | ||
}; | ||
Conversation.prototype.muteOn = function (to, from) { | ||
return this.mute(true, to, from); | ||
}; | ||
Conversation.prototype.muteOff = function (to, from) { | ||
return this.mute(false, to, from); | ||
}; | ||
return Conversation; | ||
@@ -473,13 +555,12 @@ }()); | ||
ConversationService.prototype.onInboundCall = function (callback, to, from) { | ||
var payload = { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
}; | ||
if (from) | ||
payload.from = from; | ||
var action = { | ||
provider: Providers.Conversation, | ||
action: 'subscribe-inbound-call-event', | ||
payload: payload, | ||
action: ConversationActions.SubscribeForInboundCalls, | ||
payload: { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
}, | ||
}; | ||
if (from) | ||
action.payload.from = from; | ||
return new RequestInterfaceForCallbacks(this.instance, action); | ||
@@ -489,3 +570,3 @@ }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var action; | ||
var action, res; | ||
return __generator(this, function (_a) { | ||
@@ -496,3 +577,3 @@ switch (_a.label) { | ||
provider: Providers.Conversation, | ||
action: 'create-conversation', | ||
action: ConversationActions.CreateConversation, | ||
payload: { | ||
@@ -508,7 +589,4 @@ neruCID: name, | ||
case 1: | ||
_a.sent(); | ||
// TODO: what if the client would need the response? | ||
// TODO: one of the solutions would be to pull all the meaningful information | ||
// TODO: out of the response and pass it to the Conversation's constructor | ||
return [2 /*return*/, new Conversation(name, this.instance)]; | ||
res = _a.sent(); | ||
return [2 /*return*/, new Conversation(res.id, name, this.instance)]; | ||
} | ||
@@ -518,4 +596,4 @@ }); | ||
}; | ||
ConversationService.prototype.getConversation = function (name) { | ||
return new Conversation(name, this.instance); | ||
ConversationService.prototype.getConversationById = function (id, name) { | ||
return new Conversation(id, name, this.instance); | ||
}; | ||
@@ -525,1 +603,2 @@ return ConversationService; | ||
export { ConversationService }; | ||
//# sourceMappingURL=conversation.js.map |
@@ -6,1 +6,2 @@ export { State } from './state.js'; | ||
export { ConversationService as Conversation } from './conversation.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,1 +6,2 @@ export { State } from './state.js'; | ||
export { ConversationService as Conversation } from './conversation.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -14,1 +14,2 @@ import { Instance } from '../instance.js'; | ||
} | ||
//# sourceMappingURL=messages.d.ts.map |
@@ -83,8 +83,8 @@ import { Providers, Actions } from './constants.js'; | ||
}, | ||
{ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}, | ||
]; | ||
filters.push({ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}); | ||
if (to.number) { | ||
@@ -124,1 +124,2 @@ filters.push({ | ||
export { Messages }; | ||
//# sourceMappingURL=messages.js.map |
@@ -17,1 +17,2 @@ import { Instance } from '../instance'; | ||
} | ||
//# sourceMappingURL=requestInterface.d.ts.map |
@@ -96,1 +96,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
export { RequestInterfaceForCallbacks }; | ||
//# sourceMappingURL=requestInterface.js.map |
@@ -10,1 +10,2 @@ import { Instance } from '../instance.js'; | ||
} | ||
//# sourceMappingURL=scheduler.d.ts.map |
@@ -45,1 +45,2 @@ import { v4 as uuid } from 'uuid'; | ||
export { Scheduler }; | ||
//# sourceMappingURL=scheduler.js.map |
@@ -13,3 +13,3 @@ import { CommandService, NeruLogger } from '../services/index.js'; | ||
hgetall: (htable: string) => Promise<any>; | ||
hmget: (htable: string, keys: [string]) => Promise<any>; | ||
hmget: (htable: string, keys: string[]) => Promise<any>; | ||
hvals: (htable: string) => Promise<any>; | ||
@@ -23,1 +23,2 @@ hget: (htable: string, key: string) => Promise<any>; | ||
} | ||
//# sourceMappingURL=state.d.ts.map |
@@ -206,3 +206,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
args = Object.keys(keyValuePairs).flatMap(function (k) { return [k, JSON.stringify(keyValuePairs[k])]; }); | ||
console.log('hset args', args); | ||
cmd = { | ||
@@ -301,1 +300,2 @@ operation: 'HSET', | ||
export { State }; | ||
//# sourceMappingURL=state.js.map |
@@ -9,1 +9,2 @@ import { Instance } from '../instance'; | ||
} | ||
//# sourceMappingURL=vonageAI.d.ts.map |
@@ -34,1 +34,2 @@ import { Providers } from './constants'; | ||
export { Overai }; | ||
//# sourceMappingURL=vonageAI.js.map |
@@ -11,1 +11,2 @@ import { Command, RequestHeaders } from '../types'; | ||
} | ||
//# sourceMappingURL=commandService.d.ts.map |
@@ -106,1 +106,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
export { CommandService }; | ||
//# sourceMappingURL=commandService.js.map |
export { CommandService } from './commandService.js'; | ||
export { NeruLogger } from './logger/index.js'; | ||
export { Utils } from './utils.js'; | ||
//# sourceMappingURL=index.d.ts.map |
export { CommandService } from './commandService.js'; | ||
export { NeruLogger } from './logger/index.js'; | ||
export { Utils } from './utils.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -13,1 +13,2 @@ import * as Transport from 'winston-transport'; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -46,1 +46,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
export { NeruLogger }; | ||
//# sourceMappingURL=index.js.map |
@@ -10,1 +10,2 @@ import TransportStream from 'winston-transport'; | ||
} | ||
//# sourceMappingURL=transports.d.ts.map |
@@ -119,1 +119,2 @@ var __extends = (this && this.__extends) || (function () { | ||
export { NeruHttpTransport }; | ||
//# sourceMappingURL=transports.js.map |
@@ -1,2 +0,1 @@ | ||
import { Headers } from 'got'; | ||
import { Config } from '../types'; | ||
@@ -6,3 +5,3 @@ export declare class Utils { | ||
constructor(config: Config); | ||
isJson(headers: Headers): boolean; | ||
isJson(headers: Record<string, string>): boolean; | ||
getExecutionUrl(func: string): string; | ||
@@ -12,1 +11,2 @@ getQueueUrl(func: string): string; | ||
} | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -55,1 +55,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
export { Utils }; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "neru-alpha", | ||
"type": "module", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "", | ||
@@ -6,0 +6,0 @@ "main": "dist/cjs/index.js", |
@@ -6,5 +6,13 @@ import { autoInjectable, container } from 'tsyringe'; | ||
import config from './config/index.js'; | ||
import { LogContext } from './types'; | ||
import { Action, ActionProviderGroup, RequestHeaders, CommandGroup, Filter, WrappedCallback, LogLevel } from './types'; | ||
import { | ||
Action, | ||
ActionProviderGroup, | ||
RequestHeaders, | ||
CommandGroup, | ||
Filter, | ||
WrappedCallback, | ||
LogLevel, | ||
LogContext, | ||
} from './types'; | ||
@@ -11,0 +19,0 @@ @autoInjectable() |
@@ -11,2 +11,38 @@ export enum Providers { | ||
export enum Events { | ||
AppKnocking = 'app:knocking', | ||
AudioSay = 'audio:say', | ||
AudioSayStop = 'audio:say:stop', | ||
AudioSayDone = 'audio:say:done', | ||
AudioPlay = 'audio:play', | ||
AudioPlayStop = 'audio:play:stop', | ||
AudioPlayDone = 'audio:play:done', | ||
AudioDTMF = 'audio:dtmf', | ||
EarmuffOn = 'audio:earmuff:on', | ||
EarmuffOff = 'audio:earmuff:off', | ||
MuteOn = 'audio:mute:on', | ||
MuteOff = 'audio:mute:off', | ||
LegStatusUpdate = 'leg:status:update', | ||
MemberJoined = 'member:joined', | ||
MemberInvited = 'member:invited', | ||
MemberLeft = 'member:left', | ||
ConversationCreated = 'conversation:created', | ||
} | ||
export enum CallState { | ||
Joined = 'joined', | ||
Invited = 'invited', | ||
} | ||
export enum MemberActions { | ||
Join = 'join', | ||
} | ||
export enum ChannelTypes { | ||
PHONE = 'phone', | ||
APP = 'app', | ||
SIP = 'sip', | ||
VBC = 'vbc', | ||
} | ||
export enum Actions { | ||
@@ -21,1 +57,8 @@ SendMessage = 'sendmessage', | ||
} | ||
export enum ConversationActions { | ||
CreateConversation = 'create-conversation', | ||
InvokeCsApi = 'invoke-cs-api', | ||
SubscribeForEvents = 'subscribe-conversation-event', | ||
SubscribeForInboundCalls = 'subscribe-inbound-call-event', | ||
} |
@@ -1,17 +0,40 @@ | ||
import type { Action, Contact, WrappedCallback } from '../types'; | ||
import { Instance } from '../instance.js'; | ||
import { Providers } from './constants.js'; | ||
import { Providers, Events, CallState, ChannelTypes, MemberActions, ConversationActions } from './constants.js'; | ||
import { RequestInterface, RequestInterfaceForCallbacks } from './requestInterface.js'; | ||
import { | ||
Action, | ||
AppKnockingEvent, | ||
Channel, | ||
Filter, | ||
SayTextParams, | ||
SayTextPayload, | ||
SayStopPayload, | ||
PlayStreamParams, | ||
PlayStreamPayload, | ||
PlayStopPayload, | ||
EarmuffPayload, | ||
MutePayload, | ||
CreateConversationPayload, | ||
AcceptInboundCallPayload, | ||
InviteMemberPayload, | ||
AddUserPayload, | ||
TransferMemberPayload, | ||
NeruPayloadWithCallBack, | ||
ChannelPhoneEndpoint, | ||
OnInboundCallPayload, | ||
} from '../types'; | ||
class Conversation { | ||
constructor(readonly name: string, private instance: Instance) { | ||
constructor(public id: string, public name: string, private instance: Instance) { | ||
this.name = name; | ||
this.id = id; | ||
this.instance = instance; | ||
} | ||
createConversation = (name, displayName): RequestInterface => { | ||
const action = { | ||
createConversation = (name: string, displayName: string): RequestInterface => { | ||
const action: Action<CreateConversationPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'create-conversation', | ||
action: ConversationActions.CreateConversation, | ||
description: 'Create new conversation', | ||
payload: { | ||
@@ -29,39 +52,37 @@ neruCID: name, | ||
acceptInboundCall = (appKnockingEvt): RequestInterface => { | ||
const user_id = appKnockingEvt.body.user.id; | ||
const knocking_id = appKnockingEvt.from; | ||
const { channel } = appKnockingEvt.body; | ||
acceptInboundCall = (appKnockingEvent: AppKnockingEvent): RequestInterface => { | ||
const user_id = appKnockingEvent.body.user.id; | ||
const knocking_id = appKnockingEvent.from; | ||
const { channel } = appKnockingEvent.body; | ||
const acceptInboundCallBody = { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: 'joined', | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}; | ||
const action = { | ||
const action: Action<AcceptInboundCallPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Accept inbound call - Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/members`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: acceptInboundCallBody, | ||
csBody: { | ||
user: { | ||
id: user_id, | ||
}, | ||
knocking_id, | ||
channel: { | ||
type: channel.type, | ||
id: channel.id, | ||
to: channel.to, | ||
from: channel.from, | ||
preanswer: false, | ||
}, | ||
state: CallState.Joined, | ||
media: { | ||
audio_settings: { | ||
enabled: true, | ||
earmuffed: false, | ||
muted: false, | ||
}, | ||
audio: true, | ||
}, | ||
}, | ||
}, | ||
@@ -72,10 +93,10 @@ }; | ||
inviteMember = (name, channel): RequestInterface => { | ||
const action = { | ||
inviteMember = (name: string, channel: Channel): RequestInterface => { | ||
const action: Action<InviteMemberPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Invite Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/members`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
@@ -87,4 +108,4 @@ neruMID: `${this.name}_${name}`, | ||
}, | ||
action: 'join', | ||
state: 'invited', | ||
action: MemberActions.Join, | ||
state: CallState.Invited, | ||
channel, | ||
@@ -98,10 +119,10 @@ }, | ||
addUser = (name): RequestInterface => { | ||
const action = { | ||
addUser = (name: string): RequestInterface => { | ||
const action: Action<AddUserPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Create User', | ||
payload: { | ||
url: '/users', | ||
method: 'POST', | ||
url: `/users`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
@@ -117,20 +138,20 @@ csBody: { | ||
transferMember = (user_id, leg_id): RequestInterface => { | ||
const action = { | ||
transferMember = (userId: string, legId: string): RequestInterface => { | ||
const action: Action<TransferMemberPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Transfer Member', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/members', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/members`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
action: 'join', | ||
action: MemberActions.Join, | ||
channel: { | ||
type: 'phone', | ||
id: leg_id, | ||
type: ChannelTypes.PHONE, | ||
id: legId, | ||
}, | ||
state: 'joined', | ||
state: CallState.Joined, | ||
user: { | ||
id: user_id, | ||
id: userId, | ||
}, | ||
@@ -143,16 +164,16 @@ }, | ||
sayText = (params): RequestInterface => { | ||
const action = { | ||
sayText = (params: SayTextParams): RequestInterface => { | ||
const action: Action<SayTextPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
description: 'Send Text', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Play text via TTS', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: 'audio:say', | ||
type: Events.AudioSay, | ||
body: { | ||
text: params.text, | ||
voice_name: params.voice_name || 'Amy', | ||
voice_name: params.voiceName || 'Amy', | ||
level: params.level || 1, | ||
@@ -166,16 +187,25 @@ queue: !!params.queue, | ||
}; | ||
if (params.language) { | ||
action.payload.csBody.body.language = params.language; | ||
} | ||
if (params.style) { | ||
action.payload.csBody.body.style = params.style; | ||
} | ||
return new RequestInterface(this.instance, action); | ||
}; | ||
sayStop = (sayId, to): RequestInterface => { | ||
const action: Action<any> = { | ||
sayStop = (sayId: string, to?: string): RequestInterface => { | ||
const action: Action<SayStopPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Send Stop Event', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: 'audio:say:stop', | ||
type: Events.AudioSayStop, | ||
body: { | ||
@@ -191,14 +221,14 @@ say_id: sayId, | ||
playStream = (params, memberId): RequestInterface => { | ||
const action = { | ||
playStream = (params: PlayStreamParams, to: string): RequestInterface => { | ||
const action: Action<PlayStreamPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Sending Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: 'audio:play', | ||
to: memberId, | ||
type: Events.AudioPlay, | ||
to: to, | ||
body: params, | ||
@@ -211,13 +241,13 @@ }, | ||
playStop = (playId, to): RequestInterface => { | ||
const action: Action<any> = { | ||
playStop = (playId: string, to?: string): RequestInterface => { | ||
const action: Action<PlayStopPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Stopping Audio Stream', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: 'audio:play:stop', | ||
type: Events.AudioPlayStop, | ||
body: { | ||
@@ -233,15 +263,19 @@ play_id: playId, | ||
earmuff = (memberId, enable): RequestInterface => { | ||
const action = { | ||
private earmuff(enable: boolean, to: string, from?: string): RequestInterface { | ||
const action: Action<EarmuffPayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Sending earmuff event', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? 'audio:earmuff:on' : 'audio:earmuff:off', | ||
to: memberId, | ||
from: memberId, | ||
type: enable ? Events.EarmuffOn : Events.EarmuffOff, | ||
to, | ||
from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id, | ||
// }, | ||
}, | ||
@@ -251,17 +285,29 @@ }, | ||
return new RequestInterface(this.instance, action); | ||
}; | ||
} | ||
mute = (memberId, enable): RequestInterface => { | ||
const action = { | ||
earmuffOn(to: string, from?: string) { | ||
return this.earmuff(true, to, from); | ||
} | ||
earmuffOff(to: string, from?: string) { | ||
return this.earmuff(false, to, from); | ||
} | ||
private mute(enable: boolean, to: string, from?: string): RequestInterface { | ||
const action: Action<MutePayload> = { | ||
provider: Providers.Conversation, | ||
action: 'invoke-cs-api', | ||
action: ConversationActions.InvokeCsApi, | ||
description: 'Mute Call', | ||
payload: { | ||
url: '/conversations/{{.ConversationId}}/events', | ||
method: 'POST', | ||
url: `/conversations/${this.id}/events`, | ||
method: `POST`, | ||
neruCID: this.name, | ||
csBody: { | ||
type: enable ? 'audio:mute:on' : 'audio:mute:off', | ||
to: memberId, | ||
from: memberId, | ||
type: enable ? Events.MuteOn : Events.MuteOff, | ||
to, | ||
from, | ||
// TODO: in open api rtc_id is mandatory | ||
// body: { | ||
// rtc_id | ||
// } | ||
}, | ||
@@ -271,8 +317,16 @@ }, | ||
return new RequestInterface(this.instance, action); | ||
}; | ||
} | ||
listenForEvents = (callback, filters): RequestInterfaceForCallbacks => { | ||
const action = { | ||
muteOn(to: string, from?: string) { | ||
return this.mute(true, to, from); | ||
} | ||
muteOff(to: string, from?: string) { | ||
return this.mute(false, to, from); | ||
} | ||
listenForEvents = (callback: string, filters: Filter[]): RequestInterfaceForCallbacks => { | ||
const action: Action<NeruPayloadWithCallBack> = { | ||
provider: Providers.Conversation, | ||
action: 'subscribe-conversation-event', | ||
action: ConversationActions.SubscribeForEvents, | ||
payload: { | ||
@@ -287,3 +341,3 @@ neruCID: this.name, | ||
onConversationCreated = (callback): RequestInterfaceForCallbacks => { | ||
onConversationCreated = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -293,3 +347,3 @@ { | ||
op: 'contains', | ||
values: ['conversation:created'], | ||
values: [Events.ConversationCreated], | ||
}, | ||
@@ -306,3 +360,3 @@ { | ||
onSay = (callback): RequestInterfaceForCallbacks => { | ||
onSay = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -312,4 +366,9 @@ { | ||
op: 'contains', | ||
values: ['audio:say'], | ||
values: [Events.AudioSay], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -319,3 +378,3 @@ return this.listenForEvents(callback, filters); | ||
onPlay = (callback): RequestInterfaceForCallbacks => { | ||
onPlay = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -325,4 +384,9 @@ { | ||
op: 'contains', | ||
values: ['audio:play'], | ||
values: [Events.AudioPlay], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -332,3 +396,3 @@ return this.listenForEvents(callback, filters); | ||
onSayStop = (callback): RequestInterfaceForCallbacks => { | ||
onSayStop = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -338,4 +402,9 @@ { | ||
op: 'contains', | ||
values: ['audio:say:stop'], | ||
values: [Events.AudioSayStop], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -345,3 +414,3 @@ return this.listenForEvents(callback, filters); | ||
onPlayStop = (callback): RequestInterfaceForCallbacks => { | ||
onPlayStop = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -351,4 +420,9 @@ { | ||
op: 'contains', | ||
values: ['audio:play:stop'], | ||
values: [Events.AudioPlayStop], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -358,3 +432,3 @@ return this.listenForEvents(callback, filters); | ||
onSayDone = (callback): RequestInterfaceForCallbacks => { | ||
onSayDone = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -364,4 +438,9 @@ { | ||
op: 'contains', | ||
values: ['audio:say:done'], | ||
values: [Events.AudioSayDone], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -371,3 +450,3 @@ return this.listenForEvents(callback, filters); | ||
onPlayDone = (callback): RequestInterfaceForCallbacks => { | ||
onPlayDone = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -377,4 +456,9 @@ { | ||
op: 'contains', | ||
values: ['audio:play:done'], | ||
values: [Events.AudioPlayDone], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -384,3 +468,3 @@ return this.listenForEvents(callback, filters); | ||
onLegStatusUpdate = (callback): RequestInterfaceForCallbacks => { | ||
onLegStatusUpdate = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -390,4 +474,9 @@ { | ||
op: 'contains', | ||
values: ['leg:status:update'], | ||
values: [Events.LegStatusUpdate], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -397,14 +486,19 @@ return this.listenForEvents(callback, filters); | ||
onMemberJoined = (callback, memberName): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
onMemberJoined = (callback: string, memberName?: string): RequestInterfaceForCallbacks => { | ||
const filters: Filter[] = [ | ||
{ | ||
path: 'type', | ||
op: 'contains', | ||
values: ['member:joined'], | ||
values: [Events.MemberJoined], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
if (memberName) { | ||
filters.push({ | ||
path: 'body.user.name', | ||
op: 'contains', | ||
path: `body.user.name`, | ||
op: `contains`, | ||
values: [memberName], | ||
@@ -416,9 +510,14 @@ }); | ||
onMemberInvited = (callback, memberName): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
onMemberInvited = (callback: string, memberName: string): RequestInterfaceForCallbacks => { | ||
const filters: Filter[] = [ | ||
{ | ||
path: 'type', | ||
op: 'contains', | ||
values: ['member:invited'], | ||
values: [Events.MemberInvited], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -435,9 +534,14 @@ if (memberName) { | ||
onMemberLeft = (callback, memberName): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
onMemberLeft = (callback: string, memberName: string): RequestInterfaceForCallbacks => { | ||
const filters: Filter[] = [ | ||
{ | ||
path: 'type', | ||
op: 'contains', | ||
values: ['member:left'], | ||
values: [Events.MemberLeft], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -454,3 +558,3 @@ if (memberName) { | ||
onDTMF = (callback): RequestInterfaceForCallbacks => { | ||
onDTMF = (callback: string): RequestInterfaceForCallbacks => { | ||
const filters = [ | ||
@@ -460,4 +564,9 @@ { | ||
op: 'contains', | ||
values: ['audio:dtmf'], | ||
values: [Events.AudioDTMF], | ||
}, | ||
{ | ||
path: `conversation_id`, | ||
op: `contains`, | ||
values: [this.id], | ||
}, | ||
]; | ||
@@ -471,24 +580,25 @@ return this.listenForEvents(callback, filters); | ||
onInboundCall(callback: string, to: Contact, from?: Contact): RequestInterfaceForCallbacks { | ||
const payload: { callback: WrappedCallback; to: Contact; from?: Contact } = { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
onInboundCall( | ||
callback: string, | ||
to: ChannelPhoneEndpoint, | ||
from?: ChannelPhoneEndpoint | ||
): RequestInterfaceForCallbacks { | ||
const action: Action<OnInboundCallPayload> = { | ||
provider: Providers.Conversation, | ||
action: ConversationActions.SubscribeForInboundCalls, | ||
payload: { | ||
callback: this.instance.wrapCallback(callback), | ||
to: to, | ||
}, | ||
}; | ||
if (from) payload.from = from; | ||
if (from) action.payload.from = from; | ||
const action = { | ||
provider: Providers.Conversation, | ||
action: 'subscribe-inbound-call-event', | ||
payload: payload, | ||
}; | ||
return new RequestInterfaceForCallbacks(this.instance, action); | ||
} | ||
async createConversation(name, displayName): Promise<Conversation> { | ||
// TODO: talk to Max about this method. Currently, it doesn't fit into execute/queue model | ||
async createConversation(name: string, displayName: string): Promise<Conversation> { | ||
const action = { | ||
provider: Providers.Conversation, | ||
action: 'create-conversation', | ||
action: ConversationActions.CreateConversation, | ||
payload: { | ||
@@ -503,13 +613,10 @@ neruCID: name, | ||
await new RequestInterface(this.instance, action).execute(); | ||
// TODO: what if the client would need the response? | ||
// TODO: one of the solutions would be to pull all the meaningful information | ||
// TODO: out of the response and pass it to the Conversation's constructor | ||
const res = await new RequestInterface(this.instance, action).execute(); | ||
return new Conversation(name, this.instance); | ||
return new Conversation(res.id, name, this.instance); | ||
} | ||
getConversation(name: string): Conversation { | ||
return new Conversation(name, this.instance); | ||
getConversationById(id: string, name: string): Conversation { | ||
return new Conversation(id, name, this.instance); | ||
} | ||
} |
@@ -90,8 +90,8 @@ import { Instance } from '../instance.js'; | ||
}, | ||
{ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}, | ||
]; | ||
filters.push({ | ||
path: 'to.type', | ||
op: 'contains', | ||
values: [to.type], | ||
}); | ||
if (to.number) { | ||
@@ -98,0 +98,0 @@ filters.push({ |
@@ -81,3 +81,3 @@ import { autoInjectable } from 'tsyringe'; | ||
hmget = async (htable: string, keys: [string]): Promise<any> => { | ||
hmget = async (htable: string, keys: string[]): Promise<any> => { | ||
const cmd = { | ||
@@ -119,3 +119,2 @@ operation: 'HMGET', | ||
const args = Object.keys(keyValuePairs).flatMap((k) => [k, JSON.stringify(keyValuePairs[k])]); | ||
console.log('hset args', args); | ||
const cmd = { | ||
@@ -122,0 +121,0 @@ operation: 'HSET', |
import { URL } from 'url'; | ||
import path from 'path'; | ||
import { Headers } from 'got'; | ||
import { inject, injectable } from 'tsyringe'; | ||
@@ -11,3 +10,3 @@ import { Config } from '../types'; | ||
isJson(headers: Headers): boolean { | ||
isJson(headers: Record<string, string>): boolean { | ||
return headers['content-type']?.includes('application/json'); | ||
@@ -14,0 +13,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
403428
168
8125