[twilio]: How to set Participant while sending message in twilio conversation and how to validate the Participant has permission to send message? - twilio

My requirement is forbid some participants not to send messages in conversation? how to achieve that?
I created a role as below and attached roleid to the coversation participant. So how to validate the participant not to send message in this conversation ?
{
"sid": "RL1XX",
"type": "CONVERSATION",
"permissions": [
"leaveConversation"
],
"url": "https://conversations.twilio.com/v1/Roles/RLXX",
"accountSid": "ACXX",
"chatServiceSid": "ISXX",
"friendlyName": "patient_basic",
"dateCreated": 1675238559.000000000,
"dateUpdated": 1675238559.000000000
}
How to implement role validations in twilio conversations?

Related

Creating short link through API and getting "API key not valid. Please pass a valid API key"

I want to create a short link through Firebase. I'm passing a valid API key that I used for notification. But I'm getting an error: API key is not valid
response is :
{
"success": true,
"message": "Link is genereated successfully",
"data": {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "firebasedynamiclinks.googleapis.com"
}
}
]
}
}
}
And my Controller is
class ShortLinkController < ApplicationController
def create
response = nil
firebase_server_api_key = Rails.application.secrets.firebase_server_api_key
response = HTTParty.post("https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=#{firebase_server_api_key}",
:body => JSON.generate(
{
dynamicLinkInfo: {
domainUriPrefix: 'https://example.page.link',
link: 'https://example.page.link/?username=\(/user?.username)&user_id=\(/user?.id',
androidInfo: {
androidPackageName: 'com.abc.example'
},
iosInfo: {
iosBundleId: 'com.example.abc',
iosFallbackLink: 'https://apps.apple.com/in/app/example/id1528494636',
iosAppStoreId: '1528494636'
}
}
}
),
:headers => { "Content-Type" => "application/json"}
)
render_success message: "Link is generated successfully", data: response
end
end
When creating the URL
Could you help me figure out what I'm missing/doing wrong
I'm not sure which API key you used, but a Firebase configuration has many keys that are used in the client-side app. Those keys allow you to for example consume dynamic links, but they won't necessarily allow you to create a new dynamic link with them.
The correct place to find your key for the REST API is described in the Firebase documentation on creating links with the REST API as:
Get your API key. You will need an API key to authenticate your requests to the API. To find your API key:
Open the Settings page of the Firebase console. If you are prompted to choose a project, select your Firebase project from the menu.
Take note of the value of the Web API Key field.

Getting Zero fee in Stripe Balance Transaction API Response

I am using Stripe API for receiving the contribution from multiple user. So I want to generate statement for our customer so they can see what exact amount, fee deduction, transaction count etc.
After looked into Stripe API I found there are two API(Stripe::Transfer and Stripe::BalanceTransaction) these can be used to fullfil my requirement.
So as per documentation Stripe API I am calling Stripe::Transfer API and this API returning correct response like below
transfer = #<Stripe::Transfer:0x3f997455ac88 id=tr_1xxxxxxxxxxxxxx> JSON: {
"id": "tr_1xxxxxxxxxxxxxxxxx",
"object": "transfer",
"amount": 9510,
"amount_reversed": 0,
"application_fee": null,
"balance_transaction": "txn_123",
"created": 1477485158,
"currency": "usd",
"date": 1477485158,
"description": null,
"destination": "acct_xxxxxxxxxxxxxx",
"destination_payment": "py_xxxxxxxxxxx",
"failure_code": null,
"failure_message": null,
"livemode": false,
"metadata": {},
"method": "standard",
"recipient": null,
"reversals": {"object":"list","data":[],"has_more":false,"total_count":0,"url":"/v1/transfers/tr_xx/reversals"},
"reversed": false,
"source_transaction": "ch_xxxxxxxxx",
"source_type": "card",
"statement_descriptor": null,
"status": "paid",
"type": "stripe_account"
}
I am calling Stripe::BalanceTransaction API to get the details particular transfer's transactions
balance_transaction_id = transfer.balance_transaction
Stripe::BalanceTransaction.retrieve(balance_transaction_id)
Getting below response
#<Stripe::BalanceTransaction:0x3f9974f2f1c8 id=txn_123> JSON: {
"id": "txn_123",
"object": "balance_transaction",
"amount": -9510,
"available_on": 1478044800,
"created": 1477485158,
"currency": "usd",
"description": null,
"fee": 0,
"fee_details": [
],
"net": -9510,
"source": "tr_xxxxxxxx",
"sourced_transfers": {"object":"list","data": [],"has_more":false,"total_count":0,"url":"/v1/transfers? source_transaction=tr_xxxx"},
"status": "available",
"type": "transfer"
}
I setup application fee(2%) and this showing correct on Stripe Dashboard but in the above response I am getting fee is 0
So how can I get fee and total_count values in this response?
You don't want to look at the transfer and its balance transaction here to get the fees. This is an automatic transfer between accounts from a destination payment so there is no fee linked to it.
You need to retrieve the original charge in source_transaction and then look at this charge's own balance_transaction and application_fee objects.
You can even use the expand feature to do this in one API call:
https://stripe.com/docs/api#expanding_objects
Regarding the total count I suspect you want the number of transactions for this user, then you need to look at this when listing all transfers to this account and add the following optional parameter to the request:
:include => ['total_count']
This would only work if you don't create manual transfers to the connected account on top of destination charges though.

Rails Drive Rest Api | Sharing file using google api client gem

I'm building an application who implements some drive functions. Now I'm trying to share a file using the google-api-ruby-client gem. I have some troubles using the next code.
#Here, I create a DriveService object and I authorize it.
#This works fine. In my app I list drive files well.
#drive = Google::Apis::DriveV3::DriveService.new
#drive.authorization = #token[:access_token]
#Here, first I create a permission object with some parameters
#Then I call create_permission to share the file to a other user
per=Google::Apis::DriveV3::Permission.new(type: "user", role: "writer",email_address: "some#gmail.com")
#drive.create_permission(file_id:"0B8XBWuVEmvN8YS01OXNUcHhOYWs",permission_object: per, fields: "id", &callback)
When I execute this code, the callback show this:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "The permission type field is required.",
"locationType": "other",
"location": "permission.type"
}
],
"code": 400,
"message": "The permission type field is required."
}
}
I can't solve this error. Can someone help me?
If I pass a permission object like the documentation says, doesn't works, so the correct form, and the only who works for me is:
user_permission = {type: "user", role: "writer", email_address: "some#gmail.com"}
#drive.create_permission(current_user.fileId, user_permission, send_notification_email: false, fields: 'id', &callback)
Since the debugger points to the #drive.create_permission line, it means it's looking for 'type' permission in that line. Try adding your field values
type: "user", role: "writer"
to that line so it will look like this:
#drive.create_permission(file_id:"0B8XBWuVEmvN8YS01OXNUcHhOYWs",type: "user", role: "writer", permission_object: per, fields: "id", &callback)
in case anyone is using the google javascript library, the field name on the permission create for the permission structure is 'resource'

Can we send multiple emails from survey monkey to same emailid

I am using an Email collector for sending survey invitations. I am directly adding the recipients in the below way while sending the survey invitations. However, I have a situation to send multiple invitations to the recipient with same emailID. How can we send multiple invitations in that case? If I include multiple emailID's in the same request, survey monkey mark it as "duplicate" and only one email will be sent.
Can we send multiple emails from survey monkey to same emailid?
POST /collectors/{id}/messages/{id}/recipients/bulk
{
"contacts": [{
"email": "user1#example.com",
"first_name": "User 1",
"last_name": "Testing"
},{
"email": "user2#example.com",
"first_name": "User 2",
"last_name": "Testing"
},{
"email": "user1#example.com",
"first_name": "User 1",
"last_name": "Testing"
}]
}
You cannot send to the same email twice, as you said, it will show up as a duplicate and only send once.
I'm not really sure the use case for sending two messages to the same email at the exact same time, but if you want to send to the same email again, you need to create a new message on that collector and add the recipient to the new message.

How do I create a user with no email address in Desire2Learn's Valence APIs?

If I want to create a new user through Desire2Learn's Valence API, but the user will not have an external email address, how must I provide the new user data?
When you create a new user, you must use the User.CreateUserData structure, and if you want the user to have no external email address, you have to provide a null value for the property:
{"UserName": "Test.User",
"FirstName": "Test",
"MiddleName": "",
"LastName": "User",
"RoleId": "103",
"OrgDefinedId": "ext-test-user",
"IsActive": true,
"ExternalEmail": null,
"SendCreationEmail": false}

Resources