-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.3] - kazoo_speech: ASR Billing Features and kazoo_asr Refactor (#6185
) * kazoo_speech: ASR Billing Features and kazoo_asr Refactor (#6055) This PR enhances the kazoo_speech application by augmenting the `kazoo_asr` abstraction as well as introduce new billing features. - Add `transcribe` field to the mailbox schema - Add and export callbacks to`gen_asr_provider` for content-types - Enhance the `kazoo_asr` behavior to handle default and accepted content types on behalf of the specific providers - Create an abstraction for ASR requests - Create account ledger entries on successful transcription as well as the impact the reseller ledgers. - Create `asr_flat_rate` module to handle flat rate billing of ASR requests. - Create quantifiers in `kz_services` for asr transcriptions. ``` "asr": { "google": { "rate": 1, "name": "Google ASR" }, "ispeech": { "rate": 1, "name": "ispeech ASR" } }, "plan": { .... "voicemails": { "mailbox": { "name": "Voicemail Box", "rate": 1.99, "cascade": true }, "transcription": { "cascade": true, "rate": 1, "name": "VMBox Transcription MRC" } }, .... ``` The only configuration change in this PR is adding the `transcribe` flag to the JSON schema. Two new callbacks have been added to `gen_asr_provider` to help facilitate a more generic approach to handling the preferred content-types for a provider as well as act as a gatekeeper and help identify if conversion is required or even currently supported for the submitted media. - preferred_content_type/0 - accepted_content_types/0 This callback is designed to return the ASR provider's preferred content-type for requests. This callback is designed to return the accepted content-types and assist in determining if the media payload will require conversion. The content-type callbacks have been added to `kazoo_asr` as well any `kapps_config` calls from the current providers in favor of keeping with the abstraction. Originally the ASR logic was hardcoded into the voicemail notify and save logic in `kvm_util`. I've removed that and replaced it with an asr_request. The `asr_request` module is designed to be a generic request type to handle creating and servicing ASR requests which are proxied with `kazoo_asr` to the configured provider.. Additionally it also handles the billing and services logic and introduces a `asr_flat_rate` module that can consult an ASR service plan item for rates. The long term vision is to create a primitive that can in the future could be augmented to handle multiple types of ASR requests apart from file conversion (i.e. streaming from an active call). I've added some placeholder fields in `#asr_req` record should metered billing be desired. `asr_flat_rate` is the only and default `billing_method` for an `asr_request`. It is patterned after jonny5 and aims to perform the following actions on an `asr_req`: - **authorize** *account and reseller have funds* - **debit** *ledger entries created for account and reseller if configured* Some ASR primitives have been gently introduced into `kz_services`: - `asr` getter methods have been added to `kzd_service_plans` and `kz_service_plans` - default quantifiers for transcribe enabled maiboxes in `services.hrl` - `kz_services_asr` module for interacting with the transcription usage ledgers * fix merge conflict * resolve additional merge conflict issues * swagger and schema doc issues * more swagger fixups * appease edoc * formatting issue * run make fmt
- Loading branch information
1 parent
61835ee
commit 37c3e4b
Showing
27 changed files
with
1,329 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
%%%----------------------------------------------------------------------------- | ||
%%% @copyright (C) 2012-2019, 2600Hz | ||
%%% @doc This Source Code Form is subject to the terms of the Mozilla Public | ||
%%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%%% | ||
%%% @end | ||
%%%----------------------------------------------------------------------------- | ||
-module(kz_services_asr). | ||
|
||
-export([fetch/1 | ||
,flat_rate/1, flat_rate/2 | ||
]). | ||
|
||
-include("services.hrl"). | ||
|
||
-define(DEFAULT_FLAT_RATE, 0). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec fetch(kz_services:services() | kz_term:ne_binary()) -> kz_json:object(). | ||
fetch(?NE_BINARY=AccountId) -> | ||
FetchOptions = ['hydrate_plans'], | ||
fetch(kz_services:fetch(AccountId, FetchOptions)); | ||
fetch(Services) -> | ||
ASRDict = kz_services_plans:foldl(fun fetch_foldl/3 | ||
,dict:new() | ||
,kz_services:plans(Services) | ||
), | ||
kz_json:from_list(dict:to_list(ASRDict)). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec fetch_foldl(kz_term:ne_binary(), kz_services_plans:plans_list(), dict:dict()) -> dict:dict(). | ||
fetch_foldl(_BookkeeperHash, [], Providers) -> | ||
Providers; | ||
fetch_foldl(_BookkeeperHash, PlansList, Providers) -> | ||
Plan = kz_services_plans:merge(PlansList), | ||
kz_json:foldl(fun(K, V, A) -> | ||
dict:store(K, V, A) | ||
end | ||
,Providers | ||
,kz_services_plan:asr(Plan) | ||
). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec flat_rate(kz_term:ne_binary()) -> kz_currency:dollars(). | ||
flat_rate(AccountId) -> | ||
flat_rate(AccountId, kazoo_asr:default_provider()). | ||
|
||
-spec flat_rate(kz_term:ne_binary(), kz_term:ne_binary()) -> kz_currency:dollars(). | ||
flat_rate(AccountId, Provider) -> | ||
Items = fetch(AccountId), | ||
kz_json:get_number_value([Provider, <<"rate">>], Items, ?DEFAULT_FLAT_RATE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.