ChannelRelativeUrl is undefinded in MS Graph API context - microsoft-graph-api

We are building a Microsoft Teams Tab app.
After User login, our app fetch the context info by the following way.
microsoftTeams.getContext((context: microsoftTeams.Context) => {
dispatch(getContextCallback({ context }))
})
and the context is like the following
{
appIconPosition: ...
appLaunchId: "..."
appSessionId: "..."
channelId: "..."
channelName: "..."
channelRelativeUrl: "..." <- **sometime it is undefined**
channelType: "..."
chatId: "..."
defaultOneNoteSectionId: "..."
entityId: "..."
frameContext: "..."
groupId: "..."
hostClientType: "..."
isFullScreen: ...
isMultiWindow: ...
isTeamArchived: ...
jsonTabUrl: "..."
locale: "..."
loginHint: "..."
meetingId: "..."
parentMessageId: "..."
ringId: "..."
sessionId: "..."
sourceOrigin: ...
subEntityId: "..."
teamId: "..."
teamName: "..."
teamSiteDomain: "..."
teamSiteId: "..."
teamSitePath: "..."
teamSiteUrl: "..."
teamTemplateId: "..."
teamType: ...
tenantSKU: "..."
theme: "..."
tid: "..."
upn: "..."
userClickTime: ...
userFileOpenPreference: ...
userLicenseType: ...
userObjectId: ...
userPrincipalName: ...
userTeamRole: ...
}
We are taking usage of channelRelativeUrl property to get the file folder connected with the channel. But from our error log, we found sometimes channelRelativeUrl is undefined?
We want to reenact the channelRelativeUrl undefined case, for example we rename the channel's name, but it did has a certain value.
So we are asking that in what kind of cases will app fail to get the channelRelativeUrl which is an undefined?

Related

RoR - Capsens/universign - SignatureField - The coordinates aren't working

I'm trying to set a transaction to Universign with the "capsens_universign" gem.
Here's my code to create the transaction:
document_from_content = Universign::Document.new(
name: 'another.pdf',
content: File.open("tmp/test.pdf").read
)
signer = Universign::TransactionSigner.new(
first_name: "Signer's first name",
last_name: "Signer's last name",
email: 'test#gmail.com',
phone_number: 'SOME_PHONE_NUMBER',
success_url: 'https://my_app.com',
signature: Universign::SignatureField.new(coordinate: [37,684], page: 5)
)
transaction = Universign::Transaction.create(
documents: [document_from_content],
signers: [signer],
options: { profile: 'default', final_doc_sent: false, handwritten_signature_mode: 0}
)
I got a code 200 response from this. I can sign the pdf BUT signature stamps are not showing in the PDF generated by Universign when the transaction is completed.
Is it because of this configuration ? Or maybe I didn't understand well the different signatures configurations.

Why am I getting "no implicit conversion of String into Integer" when trying to get Nested JSON attribute?

My Rails app is reading in JSON from a Bing API, and creating a record for each result. However, when I try to save one of the nested JSON attributes, I'm getting Resource creation error: no implicit conversion of String into Integer.
The JSON looks like this:
{
"Demo": {
"_type": "News",
"readLink": "https://api.cognitive.microsoft.com/api/v7/news/search?q=european+football",
"totalEstimatedMatches": 2750000,
"value": [
{
"provider": [
{
"_type": "Organization",
"name": "Tuko on MSN.com"
}
],
"name": "Hope for football fans as top European club resume training despite coronavirus threat",
"url": "https://www.msn.com/en-xl/news/other/hope-for-football-fans-as-top-european-club-resume-training-despite-coronavirus-threat/ar-BB12eC6Q",
"description": "Bayern have returned to training days after leaving camp following the outbreak of coronavirus. The Bundesliga is among top European competitions suspended."
}
}
The attribute I'm having trouble with is [:provider][:name].
Here's my code:
def handle_bing
#terms = get_terms
#terms.each do |t|
news = get_news(t)
news['value'].each do |n|
create_resource(n)
end
end
end
def get_terms
term = ["European football"]
end
def get_news(term)
accessKey = "foobar"
uri = "https://api.cognitive.microsoft.com"
path = "/bing/v7.0/news/search"
uri = URI(uri + path + "?q=" + URI.escape(term))
request = Net::HTTP::Get.new(uri)
request['Ocp-Apim-Subscription-Key'] = accessKey
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
response.each_header do |key, value|
# header names are coerced to lowercase
if key.start_with?("bingapis-") or key.start_with?("x-msedge-") then
puts key + ": " + value
end
end
return JSON(response.body)
end
def create_resource(news)
Resource.create(
name: news['name'],
url: news['url'],
description: news['description'],
publisher: news['provider']['name']
)
end
I looked at these questions, but they didn't help me:
Extract specific field from JSON nested hashes
No implicit conversion of String into Integer (TypeError)?
Why do I get "no implicit conversion of String into Integer (TypeError)"?
UPDATE:
I also tried updating the code to:
publisher: news['provider'][0]['name'], but I received the same error.
because "provider" is an array.
it should be accessed with index.
[:value][0][:provider][0][:name]
same goes with "value".

Rails Active Storage + AWS Rekognition: How to get IO file

I'm trying to integrate AWS Rekognition into my Rails app. After the user uploads his avatar via Active Storage, Rekognition should show some info about it.
def update
respond_to do |format|
if #user.update(user_params)
if #user.images.attached?
Aws.config.update({
region: 'us-west-2',
credentials: Aws::Credentials.new('ACCESS_KEY', 'SECRET_KEY')
})
rekognition = Aws::Rekognition::Client.new(region: Aws.config[:region], credentials: Aws.config[:credentials])
img = #user.images.first. # original was: File.read(ARGV.first)
#detect faces
resp = rekognition.detect_faces({
image: { bytes: img },
attributes: ["ALL"], # What attributes to return
})
resp.face_details[0].emotions.each do |emo|
puts emo.type + " " + emo.confidence.to_i.to_s #=> Strings "HAPPY", "SAD", "ANGRY"
end
end
end
end
However, I get the error
expected params[:image][:bytes] to be a String or IO object, got value #<ActiveStorage::Attachment id: 4, name: "images", record_type: "User", record_id: 47, blob_id: 9, created_at: ""> (class: ActiveStorage::Attachment) instead.
How can I get the image file property into AWS Rekognition?
There is two way to pass image to Aws::Rekognition.
AWS S3 image url and name
resp = rekognition.detect_faces(
{image:
{s3_object:
{bucket: `bucket name`,
name: `pull path of file`,
},
}, attributes: ['ALL'],
}
)
Via Image object
rekognition.detect_faces({
image: { bytes: File.read(`path of file`) }
})
in your case you are passing ActiveStorage object that can't parse by AWS. that's why it throw error.

How to get input steps ouput in jenkins-pipeline

I used in my pipeline a input steps as you can see below :
input(
message : "some message",
parameters: [
[$class: 'ChoiceParameterDefinition',
choices: string ,
description: 'description',
name:'input'
]
]
)
I wanted to use the name input that I configure to get the value put in the input like this ${input}, but it didn't work. I also tried to put it in a var like this :
def reg = input : messages : "", paramaters: [...]
But It doesn't work either, so I don't understand how I can get the param that the user chose and didn't find how to do in the do.
Regards,
When using ChoiceParameterDefinition remember to define choices as string delimited with \n. You can assign value returned by input(...) step to a variable and use it later on. Take a look at following example:
node {
stage('Test') {
def reg = input(
message: 'What is the reg value?',
parameters: [
[$class: 'ChoiceParameterDefinition',
choices: 'Choice 1\nChoice 2\nChoice 3',
name: 'input',
description: 'A select box option']
])
echo "Reg is ${reg}"
}
}
In this example I define a single select with 3 options. When I run this pipeline, I get this popup to select one of three options:
I pick the first one and pipeline finishes with following console output:
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] input
Input requested
Approved by admin
[Pipeline] echo
Reg is Choice 1
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Try use this code:
def userInput = input(id: 'userInput', message: 'some message', parameters: [
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description', name:'input'],
])
VARAIBLE = userInput
It's work For me.
If you need add more ChoiceParameterDefinition code should look like that:
def userInput = input(id: 'userInput', message: 'some message', parameters: [
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description1', name:'input1'],
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description2', name:'input2'],
])
VARAIBLE1 = userInput['input1']
VARAIBLE2 = userInput['input2']

Jenkinsfile Groovy Pipeline Text Parameter Whitespace

currently I wish to added a multliline text parmeter to a groovy pipeline. If the text parameter is not left column alighed (no space before paramter), then whitespace is injected into the text parameter list.
Any ideas on how to resolve this?
Here is the code
#!/usr/bin/env groovy
node {
def startTime = new Date()
println "Build start time : " + startTime
// Load system parameters
def projectProperties = [
[$class: 'EnvInjectJobProperty', info: [loadFilesFromMaster: false, secureGroovyScript: [classpath: [], sandbox: false, script: '']], keepBuildVariables: true, keepJenkinsSystemVariables: true, on: true]
]
// Set project parameters
projectProperties.add(parameters([
string(name: 'infraRepo', description: 'Repo Name', defaultValue: 'my-infrastructure' ),
string(name: 'infraBranch', description: 'Repo Branch', defaultValue: 'develop' ),
string(name: 'projectName', description: 'Project name', defaultValue: 'think-more' ),
// Text field not left side aligned now whitespace will be injected
text(name: 'ecrRepoAndVersion', description: 'ECR Docker name and version number',
defaultValue:'''address=3.0.1
address-details=3.0.1
auth=3.2.1'''),
choice(name: 'clusterName', description: 'Ecs cluster name', choices: '---Select---\nblue-ci\ngreen-ci', defaultValue: '---Select---'),
]))
properties(projectProperties)
// Print system variables
sh 'env | sort'
}
And here is an image of how the Jenkins Job UI looks after this pipeline is executed. Note the whitespace in the ecrRepoAndVersion field.
Thank you - that worked perfectly.
text(name: 'ecrRepoAndVersion', description: 'ECR Docker name and
version number',defaultValue:"""address=3.0.7-RC\n
address-details=3.0.3-RC\nauth=3.2.3-RC""")
Setting aside the need for this logic, I would add a bit more readability and ease of maintenance by joining a list of items, instead of verbatim specification:
def ecrRepoAndVersionItemsDefault = [
"address=3.0.7-RC",
"address-details=3.0.3-RC",
"auth=3.2.3-RC",
]
...
// then construct an ArrayList
def jobParams = []
jobParams << ...
...
jobParams << text(
name: 'ecrRepoAndVersion',
description: 'ECR Docker name and version number',
defaultValue: ecrRepoAndVersionItemsDefault.join('\n')
)
// then add the properties
...
projectProperties.add(parameters(jobParams))
...
properties(projectProperties)
...
// etc.

Resources