I need some help setting up a bot. I'm really newbie in this not
familiar alot with python but I am with perl and php.
a. I created a bot thru the kik
b. I ran pip install kik on my server
c. I created the test code
requests.post(
'https://api.kik.com/v1/config',
auth=('', ''),
headers={
'Content-Type': 'application/json'
},
data=json.dumps({
"webhook": "https://example.com/incoming",
"features": {
"manuallySendReadReceipts": False,
"receiveReadReceipts": False,
"receiveDeliveryReceipts": False,
"receiveIsTyping": False
}
})
)
I filled in username, api key and I created a web hook to a test script in perl that prints hello world.
What do I work with the above code?
How do I run it on the server. Does it have to be continually running and if so how.
Also on my server its running python 2.6. Is that ok.
Thank-you
David
strong text
I solved it:
I added at the beginning of the code:
import requests;
import json;
Related
I'm very (very) novice at playing with the Slack api - so be gentle and use short words. So far I have managed to set up a simple system that can post to our Slack channel. All well and good, but the icon associated with the posts is the default. How do I go about setting a different icon or even one I create myself?
Here is the basic code (snagged from a tutorial listed on teh Slack api dev site):
import requests
import json
url = 'https://slack.com/api/chat.postMessage'
token = 'xoxb-00000000000etc'
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(token)}
def send_message(message_text):
message = {'channel': '#channel_name', 'text': message_text}
requests.post(url, headers=headers, data=json.dumps(message))
send_message('beep boop - this is the OMS bot calling')
Many thanks...
To set the icon image for your message you can simple provide the property icon_url with a URL to an image.
Example:
message = {'channel': '#channel_name', 'text': message_text, 'icon_url': 'https://img.icons8.com/emoji/96/000000/penguin--v2.png'}
You can see all available properties on the official documentation page for the API method chat.postMessage.
Since you said you very a beginner allow me to make two additional suggestions.
1 - The offical Slack library
There is an official Slack library for Python which makes thinks much easier, e.g. you don't need to deal with the requests library and HTTP headers. You find it here: https://github.com/slackapi/python-slackclient
2 - Slack token in environment variables
For security reasons it is good practice to put your slack token in an environment variable. That way you also can check in your code into github etc.
Updated example
Here is your example with the two suggested improvements:
import slack
import os
client = slack.WebClient(token=os.environ['SLACK_TOKEN'])
response = client.chat_postMessage(
channel='general',
text='beep boop - this is the OMS bot calling',
icon_url='https://img.icons8.com/emoji/96/000000/penguin--v2.png'
)
When passing icon_url or icon_emoji to a bot, remember that the scope chat:write.customize is required. Otherwise it will have no effect.
since this morning, I'm receiving the following error from Google Cloud Platform when transcribing audio to text:
{ Error: RecognitionAudio not set.
at Operation._unpackResponse (/usr/src/app/node_modules/google-gax/build/src/longRunningCalls/longrunning.js:145:31)
at noCallbackPromise.currentCallPromise_.then.responses (/usr/src/app/node_modules/google-gax/build/src/longRunningCalls/longrunning.js:131:18)
at <anonymous> code: 3 }
Please note that I have not changed anything in my code, and this code was working perfectly before this. The code is as follows:
const client = new speech.SpeechClient();
client.longRunningRecognize({
config: {
encoding: "FLAC",
enableWordTimeOffsets: true,
languageCode: "en-US"
},
audio: {
uri: "gs://some-cloud-bucket/audiofile.flac"
}
})
As you can see, for RecognitionAudio I'm sending a Google cloud URI as described in their docs here: https://cloud.google.com/speech-to-text/docs/reference/rest/v1/RecognitionAudio
I have confirmed that both the bucket and audiofile exist. Keep in mind this was working fine yesterday.
I have no clue where to look in order to solve this error. Cloud status says their platforms are up and running and are having no issues.
Any of you guys experiencing the same problem? Or am I simply doing something wrong all of a sudden? E.g. using something deprecated that was patched today?
If anyone could point me in the right direction, that'd be awesome. Thank you in advance.
Right. So 11 minutes after posting this issue the service started working again. 🤦🏻♂️
They have been down since (at least) 2019-09-18 08:21:01 UTC which translates to about 7 hours.
For anyone reading this, the code above should be fine and working as intended.
SITUATION:
So i followed a 3 video short tutorial by sentdex on youtube named "Alexa Skills w/ Python and Flask-Ask" parts 1, 2 and 3. Basically when i run this skill, alexa will read me the first 10 headlines from reddit.com/ r/ worldnews (cant give more than 8 URL for this post unfortunately).
ERROR I'M HAVING:
I followed all steps and i keep getting this error when i test it out in the Amazon Alexa development site saying: "There was a problem with the requested skill's response". One issue i have is that the alexa development console has been updated a few months ago and is completely different so i have no clue if i did something wrong or not. All the youtube videos i have seen are on the old version which has a different way of doing things. I'm going to outline exactly what i have done and hopefully u guys could point what i did wrong.
WHAT I TRIED:
I will also like to mention that i have tried replacing the contents of the get_headlines function with a return command that returns a string for alexa to say like: "it works". But i got the same error message on the development site. So I'm guessing that my code is fine but i might have configured the setting in my alexa dev account wrong. Below, i have included pictures of every step i have done for this simple program.
EXACTLY STEPS I HAVE TAKEN:
1) I have installed flask, flask-ask, and unidecode with the pip installer
2) I downloaded ngrok to host my site
3) CODE: This is the code i have ran (took out my reddit username and password for obvious reasons). It has no errors and the homepage runs fine. So i guess there is no issue with the code itself.
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/big_reader")
def get_headlines(): # DESCRIPTION: get_headlines function will grab the headlines from redit and then its going "stringify" all the headlines together
# 1) LOG INTO REDDIT API
user_pass_dict = {
'user': 'ENTER_YOUR_REDDIT_USERNAME',#'ENTER_YOUR_USERNAME',
'passwd': 'YOUR_REDDIT_PASSWORD',
'api_type': 'json'
}
# Requesting a session from api
sess = requests.Session()
sess.headers.update( {'User-Agent': 'I am testing Alexa Here'} )
sess.post('https://www.reddit.com/api/login', data=user_pass_dict)
time.sleep(1)
url = 'https://reddit.com/r/worldnews/.json?limit=10'
html = sess.get(url)
data = json.loads(html.content.decode('utf-8'))
titles = []
for listing in data['data']['children']:
titles.append( unidecode.unidecode(listing['data']['title']) )
titles = '...'.join([i for i in titles])
return titles
################################# ALEXA STUFF ###################################################################################################
#app.route('/')
def homepage():
return "This is the Homepage"
# A) ALEXA ASKS SOMETHING:
#ask.launch
def start_skill():
welcome_message = 'Sup, You want some news?'
return question(welcome_message)
# B) MY RESPONSE:
#ask.intent("YesIntent")
def share_headlines():
headlines = get_headlines()
headline_msg = 'The current world news headlines are {}'.format(headlines) #string format the headlines?
return statement(headline_msg)
#ask.intent("NoIntent")
def no_intent():
bye_text = 'bye'
return statement(bye_text)
# RUN
if __name__ == '__main__':
app.run(debug=True)
4) PICTURES OF HOW I SET UP MY ALEXA SKILL: Here are 10 images that shows exactly what my alexa developer web page looks like
https://ibb.co/ZdMdgGF <-- my yes intent
https://ibb.co/4N4JygL <-- the JSON editor screen of my skill
https://ibb.co/c2HDw8h <-- What my interface screen looks like
https://ibb.co/BP6ck2L <--how my ngrok looks after running: ngrok http 5000
https://ibb.co/3k5J7wZ <--copying my ngrok https address to alexa endpoint.
https://imgur.com/H6QGWOo <--i even tried adding "/big_reader" at the end of it.
https://ibb.co/3s3tVQH <--the build was successful
https://ibb.co/wgF7GQ4 <--I tried to start the big reader skill and got error
I had the same problem.
I fixed it by downgrading cryptography to 2.1.4 with pip install cryptography==2.1.4
I'm hosting my own skill backend on a Raspberry Pi, using ngrok to create a tunnel between Amazon and localhost. For me this issue went away when I created and logged into my ngrok account, cut and pasted the ./ngrok authtoken into the Linux command line, and ran the command to create the authorisation token yaml file.
I am trying to run the sample AWS-Lex-Web-UI from the https://github.com/awslabs/aws-lex-web-ui#sample-site
As per the directions i am able to create the cognito pool id and also saved in the chatbot-ui-loader-config.json and tried with npm start. Server started at localhost:8000 but i am not able to run any one of the bot command.
Does anybody already implemented in the WEB-UI part using the sample example. I want to export my bot from AWS-LEX to any one of the local server.
chatbot-ui-loader-config.json:
{
"cognito": {
"poolId": "us-east-1:b3bxxxx-xxxx-45c7-xxxx-9xxxxxxxx"
},
"lex": {
"botName": "DataBot",
"initialText": "You can ask me for help rendering a file. Just type \"Render File\" or click on the mic and say it.",
"initialSpeechInstruction": "Say 'Render a file' to get started."
},
"polly": {
"voiceId": "Salli"
},
"ui": {
"parentOrigin": "",
"toolbarTitle": "File Processor"
},
"recorder": {
"preset": "speech_recognition"
}
}
Checkout the browser console for any errors. It helped me while I was trying this one out.
Here are some of the things that I experienced before I was able to try this out locally:
IAM permissions should be properly set such as cognito pools should have access to the Lex or that Polly should be able to access Lex.
Federated identities versus User Pools - I had to use Federated Identity pool.
I had the same issue. I followed this guide to solve my problem.
This issue is more related to setting proper permission for Amazon Cognito Pools. It can be checked from browser console as pointed out in the above answer.
The above link provide step by step guide.
I am trying to send a template email with Postmark in Node.js
I created a template on the Postmark App website. I've looked through their documentation, but cannot find any way to go about sending a templated email.
Documentation Sources:
http://blog.postmarkapp.com/post/125849089273/special-delivery-postmark-templates
http://developer.postmarkapp.com/developer-api-templates.html
I've tried a variety of methods, including:
client.emailWithTemplate("jenny#example.com",
"bob#example.com",<template-id>, {
"link" : "https://example.com/reset?key=secret",
"recipient_name" : "Jenny"
});
TypeError: Object # has no method 'emailWithTemplate'
client.sendEmail({
"TemplateModel" : {
"customer_name" : "Jenny",
},
"TemplateId" : 6882,
"From": "info#formulastocks.com",
"To": "lrroberts0122#gmail.com",
}, function(error, success) {
if(error) {
console.log(error);
} else {
console.log(success);
}
});
Console Log Error: { status: 422,
message: 'A \'TemplateId\' must not be used when sending a non-templated email.',
code: 1123 }
Thanks!
I'm the current maintainer of the node.js library (as well as one of the engineers that worked on Postmark Templates).
One of the possible reasons the original snippet doesn't work is that you could be using an older version of Postmark.js. We added the template endpoint capabilities in version 1.2.1 of the node.js package.
In the package.json file for your project you should make sure to update it to use version 1.2.1 or greater of the postmark.js library. If you've been using an older version of the library, you'll also need to run npm update
Also note that if you click "Edit Template" in the Postmark UI, and then "API Snippets," the UI provides a completed snippet for a number of languages (including node.js).
If all else fails, please contact support and we'll be happy to help you solve this issue.