APIs for Custom Channel
Once you've configured your custom channel and distributed a flow via your custom channel, you would want to start the flow for your users and pipe their responses for further processing.
To achieve to this, you can use our REST endpoints for custom channels.
REST APIs
Start a new session
This API is used to start a new session for your users
Request
- URL -
https://stage-askribe-askribe-ohlibf5r4a-el.a.run.app/api/v1/consumer/custom-channel/start - Request Method -
POST - Headers -
"Content-Type": "application/json" - Body
askribeKey- Type:
String - Required
- Obtain the API key required to connect with Askribe servers from the
Settingssection in your Askribe flow dashboard.
- Type:
configId- Type:
String - Required
- This is the ID of your API / SDK Distribution. This can be obtained from your flow's distribution list
- Type:
context- Type:
Map<String, VariableData> - Optional
- Description: Pass a list of Key-Value pairs to be substituted in the flow
- Type:
contactId- Type:
String - Optional
- Description: Pass your user's id. This can be obtained by using our CDP APIs
- Type:
language- Type:
String - Optional
- Description: Use this parameter to set the language of the flow
- Type:
Response
- Response Type -
application/json - Body
customChannelResponseDTOType- Type:
Enum - Possible Values
START_FLOW_RESPONSE- Sent when the session was started successfully and you need to render the block for your usersSTART_FLOW_LINK- Sent when the session was started successfully and you need to render a link for your users to start the flow. You can get the link from thecontentfield.FLOW_SCHEDULED- Sent when the session has been successfully scheduled for the futureERROR- Sent when an error has occurred. You can get more details about the error fromcontentfield
- Type:
sessionId- Type:
String - Description: This is the ID of the session. Use this for all further communications with our system
- Type:
nodeId- Type:
String - Description: This is the ID of the block. It is only sent when the type of response is
START_FLOW_RESPONSE.
- Type:
newEditNodeType- Type:
Enum - Description: This is the type of block. It is only sent when the type of response is
START_FLOW_RESPONSE. - Possible Values
STATEMENTTEXT_INPUTNUMERIC_INPUTURL_INPUTEMAIL_INPUTPHONE_NUMBER_INPUTDATE_TIMEUPLOADLISTEN- Note that the content would be empty for this caseOPTIONS- Two additional parametersisMultipleandoptionswill be sent for this
- Type:
content- Type:
String - Description: This is the main content of the block
- Type:
isMultiple- Type:
String - Description: Sent when
newEditNodeType = OPTIONS. Indicates whether the user is allowed to select multiple options
- Type:
options- Type:
List<{content: string, buttonId: string}> - Description: Sent when
newEditNodeType = OPTIONS. This contains the data to display interactive buttons / options to your user
- Type:
Get next block
After you have started a new session using the previous API and rendered a block for your users, you might want to render the next block.
Request
- URL -
https://stage-askribe-askribe-ohlibf5r4a-el.a.run.app/api/v1/consumer/custom-channel/next - Request Method -
POST - Headers -
"Content-Type": "application/json" - Body
askribeKey- Type:
String - Required
- Obtain the API key required to connect with Askribe servers from the
Settingssection in your Askribe flow dashboard.
- Type:
sessionId- Type:
String - Required
- Description: This is the ID of the session. You can get it from the response of the
/startrequest
- Type:
nodeId- Type:
String - Required
- Description: This is the ID of the block. You can get it from the response of the previous request
- Type:
response- Type:
String - Optional
- Description: This is the response given by the user. Use it when the block type is
TEXT_INPUTNUMERIC_INPUTURL_INPUTEMAIL_INPUTPHONE_NUMBER_INPUTDATE_TIMELISTEN- (In case of textual response)OPTIONS- (In case ofisMultiple = false)
- Type:
responses- Type:
List<String> - Optional
- Description: This is the response given by the user when block type is
OPTIONSandisMultiple = true
- Type:
imageUrlsvideoUrlsfileUrlsaudioUrls- Type:
List<String> - Optional
- Description: This is the response given by the user when block type is
UPLOADor block type isLISTENand response is non-textual
- Type:
Response
- Response Type -
application/json - Body
customChannelResponseDTOType- Type:
Enum - Possible Values
NEXT_BLOCK- The request was successful and you need to render the new block for your usersERROR- Sent when an error has occurred. You can get more details about the error fromcontentfieldEND_FLOW- Sent when the session has ended
- Type:
- All the other parameters are the same as
/startrequest
Exit flow
Use this API to exit out of a flow
Request
- URL -
https://stage-askribe-askribe-ohlibf5r4a-el.a.run.app/api/v1/consumer/custom-channel/exit - Request Method -
POST - Headers -
"Content-Type": "application/json" - Body
askribeKey- Type:
String - Required
- Obtain the API key required to connect with Askribe servers from the
Settingssection in your Askribe flow dashboard.
- Type:
sessionId- Type:
String - Required
- Description: This is the ID of the session. You can get it from the response of the
/startrequest
- Type:
Response
- Response Type -
application/json - Body
customChannelResponseDTOType- Type:
Enum - Possible Values
END_FLOW- The request was successful and the flow has endedERROR- Sent when an error has occurred. You can get more details about the error fromcontentfield
- Type:
Get languages
You can get all languages of the flow using this API
Request
- URL -
https://stage-askribe-askribe-ohlibf5r4a-el.a.run.app/api/v1/consumer/custom-channel/get-languages - Request Method -
POST - Headers -
"Content-Type": "application/json" - Body
askribeKey- Type:
String - Required
- Obtain the API key required to connect with Askribe servers from the
Settingssection in your Askribe flow dashboard.
- Type:
sessionId- Type:
String - Required
- Description: This is the ID of the session. You can get it from the response of the
/startrequest
- Type:
Response
- Response Type -
application/json - Body
customChannelResponseDTOType- Type:
Enum - Possible Values
LIST_LANGUAGES- The request was successful. You will get the response inlanguagesfieldERROR- Sent when an error has occurred. You can get more details about the error fromcontentfield
- Type:
languages- Type:
List<{id: string, name: string}> - Description: Contains the name and id of the languages present in the flow
- Type:
Set language
You can set the language of a session using this API
Request
- URL -
https://stage-askribe-askribe-ohlibf5r4a-el.a.run.app/api/v1/consumer/custom-channel/set-language - Request Method -
POST - Headers -
"Content-Type": "application/json" - Body
askribeKey- Type:
String - Required
- Obtain the API key required to connect with Askribe servers from the
Settingssection in your Askribe flow dashboard.
- Type:
sessionId- Type:
String - Required
- Description: This is the ID of the session. You can get it from the response of the
/startrequest
- Type:
languageId- Type:
String - Required
- Description: This is the ID of the language. You can get it from the response of the
/get-languagesrequest
- Type:
Response
- Response Type -
application/json - Body
- The response is same as
/nextrequest
- The response is same as
Transformation
Upon calling the /start, /next or /set-language API, you might receive a JSON which contains the block that you want to render for your users.
You can use simple programming constructs to achieve the transformation. As an example, we'll show you how to transform the response obtained from Askribe to render the blocks in Intercom's Canvas Kit
Example code
const response = getResponseFromAskribe(); // Call the appropiate API using this response
let intercomResponse = {};
if (response != null) {
const {
customChannelResponseDTOType,
newEditNodeType,
isMultiple,
content,
options,
nodeId
} = response;
if (
customChannelResponseDTOType === "START_FLOW_RESPONSE" ||
customChannelResponseDTOType === "NEXT_BLOCK"
) {
if (newEditNodeType === "STATEMENT") {
intercomResponse = {
type: "text",
text: content
};
} else if (
[
`TEXT_INPUT`,
-`NUMERIC_INPUT`,
-`URL_INPUT`,
-`EMAIL_INPUT`,
-`PHONE_NUMBER_INPUT`
].includes(newEditNodeType)
) {
intercomResponse = {
type: "input",
id: nodeId,
label: content
};
} else if (newEditNodeType === "OPTIONS") {
if (isMultiple) {
intercomResponse = {
type: "checkbox",
id: nodeId,
label: content,
options: options.map((it)=>({{
type: "option",
id: it.buttonId,
text: it.content
}}))
};
} else {
intercomResponse = {
type: "dropdown",
id: nodeId,
label: content,
options: options.map((it)=>({{
type: "option",
id: it.buttonId,
text: it.content
}}))
};
}
}
}
} else {
console.log("An error has occurred");
}