KoreBotSDK 0.0.9

KoreBotSDK 0.0.9

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布日期最新版本发布日期2018年2月
SPM支持SPM

Srinvas Vasadi维护。



  • Srinivas Vasadi

概述

This SDK allows you to talk to Bots over a web socket.

先决条件

- SDK app credentials (Create your SDk app in bot admin console to aquire the client id and client secret.
- jwt assertion generation methodology. ex: service which will be used in the assertion function injected as part of obtaining the connection.

运行演示应用

Run pod install in the KoreBotSDKDemo project folder.
Open KoreBotSDKDemo.xworkspace in Xcode.
Run the app in xcode

将KoreBotSDK集成到您的应用中

2. 初始化Bot客户端

import KoreBotSDK
var self.botClient: BotClient!
let token: String = "bearer Y6w*******************"
let botInfo: NSDictionary = ["chatBot":"Kora","taskBotId":"st-******"]
self.botClient = BotClient(botInfoParameters: botInfo)

3. 已登录用户

a. You need to have secure token service hosted in your environment which returns the JWT token.
b. Replace "jwtUrl" variable value with your STS endpoint in constants.swift file
c. self.botClient.connectAsAuthenticatedUser(jwtToken, success: { [weak self] (botClient) in
        // listen to RTM events

        }, failure: { (error) in

    })

4. 匿名用户登录

let clientId: String = "YOUR_SDK_CLIENTID"
self.botClient.connectAsAnonymousUser(clientId, success: { [weak self] (client) in
        // listen to RTM events

    }, failure: { (error) in

})

5. 发送消息

botClient.sendMessage("Tweet hello", options: [])

6. 监听事件

self.botClient.onMessage = { [weak self] (object) in
}
self.botClient.onMessageAck = { (ack) in
}
self.botClient.connectionDidClose = { (code) in
}
self.botClient.connectionDidEnd = { (code, reason, error) in
}

7. 订阅推送通知

self.botClient.subscribeToNotifications(deviceToken, success: { (staus) in
    // do something
}, failure: { (error) in
})

8. 取消订阅推送通知

self.botClient.unsubscribeToNotifications(deviceToken, success: { (staus) in
    // do something
}, failure: { (error) in
})

9. 示例

a. As a logged in user
    self.botClient.connectAsAuthenticatedUser(jwtToken, success: { [weak self] (botClient) in
            botClient.connectionWillOpen = { () in

            }

            botClient.connectionDidOpen = { () in

            }

            botClient.onConnectionError = { (error) in

            }

            botClient.onMessage = { (object) in

            }

            botClient.onMessageAck = { (ack) in

            }

            botClient.connectionDidClose = { (code) in

            }

            botClient.connectionDidEnd = { (code, reason, error) in

            }
        }, failure: { (error) in

    })

b. As a anonymous user
    self.botClient.connectAsAnonymousUser(clientId, success: { [weak self] (botClient) in
        botClient.connectionWillOpen = { () in

        }

        botClient.connectionDidOpen = { () in

        }

        botClient.onConnectionError = { (error) in

        }

        botClient.onMessage = { (object) in

        }

        botClient.onMessageAck = { (ack) in

        }

        botClient.connectionDidClose = { (code) in

        }

        botClient.connectionDidEnd = { (code, reason, error) in

        } 
    }, failure: { (error) in

    })

许可协议

版权所有 © Kore, Inc. MIT 许可协议;有关更多详细信息,请参阅LICENSE。