How to access data field in Dialogflow? - ios

As the Dialogflow documentations states, the data field represents
Additional data required for performing the action on the client side.
The data is sent to the client in the original form and is not
processed by Dialogflow.
How should one access it in the iOS framework?
request?.setMappedCompletionBlockSuccess({ (request, response) in
...
}
I couldn't find it in the response object and can't find any documentation for iOS.
Thanks.

Your question is a bit vague (can you edit and narrow it down?), but i think you got it the other way round, what that snippet of documentation that you pasted means is that you are supposed to send that payload to DialogFlow and it will forward it to a connected Client (e.g Messenger, Slack etc) un-touched. It simply means that DialogFlow assumes that you know what you are doing.
Here is a sample Fulfilment response to DialogFlow in JS
module.exports.sendGenericMessageWithText = function(message) {
return {
data: {
facebook: [
{
text: message
]
}
}
}

Related

Send message to self-Chat in Microsoft Teams using Graph API

I'm trying to send a message to my self-Chat in Microsoft Teams through a Graph API call but can't find the ID of this specific chat. For the record, this type of chat was introduced to Teams in June, 2022.
By reading the Graph API documentation, it's possible to list all chats available for a specific user using the following API call (in this case, myself):
[GET] https://graph.microsoft.com/beta/me/chats/
Yet, I can't seem to find my self-chat in there. The chat itself is already created since I wrote messages in it but it doesn't appear in the call response.
I've tried to filter the results by most recent results, by filtering on my own name or by filtering by ChatType, but it was still missing.
Is anyone aware of a way to get the ID of a user self-chat in Microsoft Teams?
Thanks!
Self chat is a special kind, You can use this endpoint to communicate with it:
https://graph.microsoft.com/v1.0/me/chats/48:notes/messages
Hope that helps :)
Answering harrywyn's question regarding the pop up notification, you can set it as unread the same as any chat like this:
EndPoint = f'https://graph.microsoft.com/v1.0/chats/48:notes/markChatUnreadForUser'
update_chat = {
"user": {
"id" : uid,
"tenantId": TENANT_ID
}
}
resp = requests.post(EndPoint, headers=headers, verify=False, json=update_chat)

How to create a "challenge" for my Cloud Functions server

I'm trying use Apple's new DeviceCheck API to verify that network calls in my app are actually coming from an uncompromised version of my app.
Documentation
After successfully verifying a key’s attestation, your server can
require the app to assert its legitimacy for any or all future server
requests. The app does this by signing the request. In the app, first
obtain a unique, one-time challenge from the server. You use a
challenge here, like for attestation, to avoid replay attacks. Then
combine the challenge with the server request to create a hash:
let challenge = <# A string from your server #>
let request = [ "action": "getGameLevel",
"levelId": "1234",
"challenge": challenge ]
guard let clientData = try? JSONEncoder().encode(request) else { return }
let clientDataHash = Data(SHA256.hash(data: clientData))
Use this hash and the key identifier that you generated earlier to
create an assertion object by calling the
generateAssertion(_:clientDataHash:completionHandler:) method:
service.generateAssertion(keyId, clientDataHash: clientDataHash) { assertion, error in
guard error == nil else { /* Handle the error. */ }
// Send the assertion and request to your server.
}
I'm trying to add this assertion functionality to my Swift function, which is a helper function that calls a Firebase Cloud Function.
I want the assertion object to be passed as data to the Cloud Function, to verify that the Cloud Function is being called from an uncompromised version of my app:
func callFunction(name: String, data: [String:Any?], completion: #escaping (HTTPSCallableResult?, Error?)->()){
var functions = Functions.functions()
functions.httpsCallable(name).call(data){ (result, error) in
completion(result, error)
}
}
(Example of callFunction() being used below):
let data: [String:Any?] = [
"gameId": self.game?.id,
"answer": answer,
"answeredAt": Date().millisecondsSince1970
]
callFunction(name: "answerQuestion", data: data){ res, err in
print("Submitted answer: \(res.debugDescription) | Error: \(err)")
if let err = err {
self.game?.question?.state = .initial
}
}
To generate the assertion object to send to my server (cloud function), it requires me to generate a challenge as stated above. However I'm not sure how to generate this challenge.
Apple says it should be "A string from your server". But I'm not sure what the string should be. Is it meant to be a dynamic string based on the user's UID? A Base64-encoded string of the user ID and a static secret string? And when I try to retrieve this string from the server, the user will just be able to read it as they can see incoming network JSON (I presume I would retrieve the string with a Cloud Function call) - so it seems pointless as it's not a secret string anymore?
Any idea how I can make the challenge work securely?
The point of the challenge is to avoid replay attacks, so it can be any randomised string. A UUID would be fine. It doesn't need to be a secret.
The challenge string is combined with the transaction data and a hash is generated. You send the hash to and you send that to generateAssertion and receive the assertion object. You then send this to your server along with the request data.
Now your server can combine the received request data with the challenge (which it knows, since it sent it to the client initially), generate the same hash and validate the attestation.
The server-side attestation article provides detail on the challenge data:
Provide a Challenge
Every time your app needs to communicate attestation data to your server, the app first asks the server for a unique, one-time challenge. App Attest integrates this challenge into the objects that it provides, and that your app sends back to your server for validation. This makes it harder for an attacker to implement a replay attack.
When asked for a challenge, provide your app with a randomized data value, and remember the value for use when verifying the corresponding attestation or assertion objects sent by the client. How you use the challenge data depends on the kind of object that you need to validate.

How to send Dialogflow an access token from Swift using ApiAi Pod

While following this tutorial: https://medium.com/#pallavtrivedi03/integrating-dialogflow-as-a-chat-bot-in-an-ios-app-e66a4c7f2723
I was unable to find out how to interact with dialogflow intents that require authentication via the swift app. Once the dialogflow path reaches a point where it needs authentication, the request is not met with a response.
I have successfully sent requests and received responses from dialogflow using the following:
func performQuery(senderId:String,name:String,text:String)
{
let request = ApiAI.shared().textRequest()
if text != "" {
request?.query = text
} else {
return
}
//print("request: ")
request?.setMappedCompletionBlockSuccess({ (request, response) in
let response = response as! AIResponse
print(response.result.parameters)
//print(response.result.action)
I am not an experienced swift user so it could be that I am missing something simple, however, I am unable to find any documentation on the topic.
Any information on ways to interact with dialogflow using oauth2 would be greatly appreciated.

Slack bot that goes out and reads data from external page then posts?

I have an external website that has some dynamic data on it that refreshes regularly. I'd like to set up a Slack bot reaches out to that site (maybe by a curl or with screen scraping) and return the first line of data into a message in a channel.
I browsed some integrations and I haven't found anything that fits the bill quite yet. I don't have control over the external site to put a send to Slack button on it.
Thanks!
Assuming the curl/scraping part works as intended, you should have no specific issue. When the user types either a slash command or a bot keyword, you can perform the scraping from your server then:
if it was a slash command, use a delayed response (you have up to 30min to respond, see documentation https://api.slack.com/slash-commands#responding_to_a_command)
If the request came from a bot, simply post the text in the channel as a standard message
It would help if you shared more details about the framework you use or even share your code
If you are writing your bot in Go, you are more than welcome to use my Slack Bot framework https://github.com/shomali11/slacker
You can easily create a bot that responds to mentions and direct messages then respond back.
For example:
package main
import (
"github.com/shomali11/slacker"
"log"
)
func main() {
bot := slacker.NewClient("<YOUR SLACK BOT TOKEN>")
bot.Command("ping", "Ping!", func(request *slacker.Request, response *slacker.Response) {
response.Reply("pong")
})
bot.Command("read <url>", "Read content of a URL", func(request *slacker.Request, response *slacker.Response) {
urlContent := readData(request.Param("url"))
response.Reply(urlContent)
})
err := bot.Listen()
if err != nil {
log.Fatal(err)
}
}
As for the readData method, reading data from external pages should be relatively straightforward in Go. Here is an example using gorequest:
request := gorequest.New()
response, body, errs := request.Get("http://example.com/").End()

Identify Request return of (id)result

I am retrieving some user date out of my iOS app (me/friens, me/events, ...) I want to forward this JSON to a server where I do some additional data processing.
The thing is that I get an answer for my me/events object without any kind of identifier:
(
{
data = (
The only thing I get is this 'data' string: But how is it possible to manipulate the JSON in the way that I get an identifier like:
(
{
events = (
Thank you very much for any kind of help!
I was wrong. Of couse this is not JSON. It is the output of a NSDictionary object. If you want to enable Facebook SSO in your Application and handle open graph data after the User logged in you just send the Facebook Id and the access_token to the server to perform additional tasks.

Resources