Channel Developers

thumbnail

Function


A Function is an API(specified by ChannelTalk) used to request features of an App.

All requests to an app follow the Function schema


A Function sends HTTP PUT requests to the Function Endpoint , which is registered to an app.

You can register the Function Endpoint in [App Settings] - [General Settings] - [Server Settings] .

Additionally, you can generate a Signing Key to check the validity of a request(whether if it came from ChannelTalk).

Your app server should provide the HTTP API to handle and response back to such requests.

HTTP API

url

{Function Endpoint registered above}

method

PUT

notes

requested from ChannelTalk to your App Server

request

header

name

notes

required

X-Signature

HMAC signature signed using the Signing Key

true

  • How to verify X-Signature

  1. Encode the signing key to hexadecimal bytes.

  2. Encode the request body to UTF-8 bytes.

  3. Using the secret key from step one and HMAC SHA-256 function, compute the digest of the value from step two.

  4. Encode the digest to base64.

  5. Compare the value from step four to the X-Signature in the request header.\

Java

body

JSON

field

type

notes

method

string

name of the specific feature to call by function(rpc name)

params

array or object

function body.json data passed by function

context

object

context info of function call.described below

context

  • Context is the background info attached by ChannelTalk.

  • You can rely on the data in context. (if you verified the X-Signature)

field

type

notes

channel

object

id:id of the channel where the function was called

caller

object

type:type of caller\|app,user,manager id:id of caller

Response

Either result or error

field

type

notes

result

object or array

response of successful status code

error

object

response of failing status code

success

JSON

failure

JSON

field

type

notes

type

string

error type

message

string

error message


You can also call a function of a different app from your app.

Send a request to the ChannelTalk API server using the Function schema described below with the ID of the app.

endpoint

app-store-api.channel.io/general/v1/apps/{appID}/functions

method

PUT

notes

calls the function of a different app installed to the channel

  • Request

    header

    name

    notes

    required

    x-access-token

    Channel token issued fromAuthentication

    true

    body

    JSON

    field

    type

    notes

    method

    string

    name of the specific feature to call by function(rpc name)

    params

    array or object

    function body.json data passed by function

  • Response

    Either result or error

    field

    type

    notes

    result

    array or object

    response of successful status code

    error

    object

    response of failing status code

    success

    JSON

    failure

    JSON

    field

    type

    notes

    type

    string

    error type

    message

    string

    error message


Native Function is a Function API provided by ChannelTalk to manipulate the resources of ChannelTalk. You can write user chat messages, read the info of a manager and etc, which are part of the ChannelTalk resources. Read below on how to call a Native Function .

url

app-store-api.channel.io/general/v1/native/functions

method

PUT

notes

call Native Function offered by ChannelTalk

  • Request

    header

    name

    notes

    required

    x-access-token

    Channel token issued fromAuthentication

    true

    body

    JSON

    field

    type

    notes

    method

    string

    name of the specific feature to call by function(rpc name)

    params

    array or object

    function body.json data passed by function

  • Response

    Either result or error

    field

    type

    notes

    result

    object

    response of successful status code

    error

    object

    response of failing status code

    success

    JSON

    failure

    JSON

    field

    type

    notes

    type

    string

    error type

    message

    string

    error message

App

registerCommands

JSON

Channel

writeGroupMessage

JSON

writeUserChatMessage

JSON

getManager

JSON

batchGetManagers

JSON

searchManagers

JSON

getUserChat

JSON

getUser

JSON

getChannel

JSON

manageUserChat

JSON

Manager

writeGroupMessageAsManager

JSON

writeUserChatMessageAsManager

JSON

writeDirectChatMessageAsManager

JSON

User

writeUserChatMessageAsUser

JSON