Out of band Self Connection
This feature allows users to connect with your app through a QR code or a dynamic link.
In addition to a regular connection, you’ll receive a callback notification once a user is connected to your app. The callback is an entry point to build your business logic, e.g., sending a welcome message.
Let’s see an example:
Generating a QR code
# Generates a QR code for the connection request
@app.chat
.generate_connection_qr
.as_png(border: 0, size: 400)
.save('/tmp/qr.png', :interlace => true)
qrdata, _ := s.chat.GenerateConnectionQR(chat.ConnectionConfig{
Expiry: time.Minute * 5,
})
// Generates a QR code for the connection request
let buf = sdk.chat().generateConnectionQR()
const fs = require(‘fs’).promises;
await fs.writeFile(’/tmp/qr.png’, buf);
Generating a dynamic link
link = @app.chat.generate_connection_deep_link("")
link, err := s.chat.GenerateConnectionDeepLink(chat.ConnectionConfig{
Expiry: time.Minute * 5, // this is required ?
})
let link = sdk.chat().generateConnectionDeepLink("")
Subscribing to new connections
# Register an observer for a connection response
@app.chat.on_connection do |res|
if res.status == "accepted"
p "successfully connected"
@app.chat.message(res.from, "Hey there! We're connected!")
end
end
s.chat.OnConnection(func(iss, status string) {
log.Println("Response received from " + iss + " with status " + status)
parts := strings.Split(iss, ":")
s.chat.Message([]string{parts[0]}, "Hi there!")
})
sdk.chat().onConnection((res: any): any => {
sdk.logger.info(`connection request ${res.status} by ${res.data.display_name}(${res.iss})`)
sdk.chat().message(res.iss, "hi there!")
exit()
})